In the constant block I see the value 0x10 = 16. Why?

Altair Forum User
Altair Forum User
Altair Employee
edited October 2020 in Community Q&A

 

Submitted by Joe on Wed, 09/07/2011 - 18:05 

Hi,

In a constant block, when I type any value between 0x1 to 0x9, the output is in decimal, i.e, between 1 to 9. If I go beyond that, like 0x10, it shows 16 as output and so on. Why?

Tagged:

Answers

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited June 2016

    Submitted by Anders89 on Wed, 09/07/2011 - 18:18.

    The constant blocks, like other VisSim blocks, accept C syntax. C uses a 0x prefix as indicating hex notation (a base 16 number). Base 16 can be useful when looking at bit patterns in binary words. Since 16 is a power of 2, each hex digit maps to the same 4-bit pattern shifted by 4*digit position. For instance, 0xF0F is 4 upper bits all 1, 4 middle bits zero and 4 lower bits all 1. This is handy when manipulating bits on an embedded target.
    Also, hex numbers are always integer typed. So prefixing with 0x is an easy way to create an integer constant in VisSim.