Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
14 years ago

Radix problem

hello.

I am beginner... and i have a problem.

i attached the picture of my simulation file.

i am confused because when i change the radix binary to decimal...

it doesn't show me the right answer i thought.

for example... the binary number 0011 have to be 3 in decimal number.

but when i change the radix binary to decimal.. it give me the strange number...

for example.. 1101 -> -3 , 1011 -> -5....

what is the problem?

6 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    You are displaying 4-bit signed integers. It sounds like what you really want is unsigned. In the Modelsim wave window, select the signal you want to display in unsigned, right click and select 'Radix' and then 'Unsigned'.

    Cheers,

    Dave
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    thanks, but what does the 'unsigned' do..?

    when i click the 'unsigned' , the nuber looks right.

    but i don't know what the 'unsigned clicking' makes unsigned.

    what is that?

    ( i'm sorry. i don't use english so.. i am not good at english.)
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    The source signal must be a std_logic_vector. This could be a signed or unsigned number - modelsim has no idea. Its basically selecting whether it unsigned or signed 2s compliment number.

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    thanks, but what does the 'unsigned' do..?

    when i click the 'unsigned' , the nuber looks right.

    but i don't know what the 'unsigned clicking' makes unsigned.

    what is that?

    --- Quote End ---

    The 4-bit signal you are looking at can be interpreted as a signed value or unsigned value. When its interpreted as a signed value, the MSB represents -2^(B-1), where B is the number of bits. For example, with B = 3-bits you get the two possible interpretations (for the same bit representation);

    
    Unsigned
    ---------
    111 = 7
    110 = 6
    101 = 5
    100 = 4
    011 = 3
    010 = 2
    001 = 1
    000 = 0
    Signed
    ---------
    011 = 3
    010 = 2
    001 = 1
    000 = 0
    111 = -1 (= -4 + 3)
    110 = -2 (= -4 + 2)
    101 = -3 (= -4 + 1)
    100 = -4  
       
    
    Note how the MSB represents -2^(B-1) = -4 in the signed version.

    You can also interpret the 4-bit values as fractional integers, where you add a decimal point. Read this wikipedia entry:

    http://en.wikipedia.org/wiki/q_%28number_format%29

    and this document:

    http://www.ovro.caltech.edu/~dwh/correlator/pdf/esc-100paper_hawkins.pdf (http://www.ovro.caltech.edu/%7edwh/correlator/pdf/esc-100paper_hawkins.pdf)

    Cheers,

    Dave
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    i'm so really appreciate !!!

    thanks! it's really helpful for me!

    --- Quote End ---

    You're welcome.

    Cheers,

    Dave