Shop OBEX P1 Docs P2 Docs Learn Events
HEX Code — Parallax Forums

HEX Code

Joe FishbackJoe Fishback Posts: 99
edited 2007-03-05 16:51 in BASIC Stamp
I understand the Hexadecimal and Binary code systems usually, but I have run into the HEX number being different than I understand. For decimal
number 708 the hexadecimal would 2C4. Why would the hexadecimal number be shown as 0x2C4 ?

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
······ Joe Fishback

-Robots are my friends-

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-03-05 16:41
    Joe,

    On a BASIC Stamp you would use $2C4…But 0x2C4 is just another way of representing a hexadecimal number that some people use. I prefer $2C4 myself. Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • allanlane5allanlane5 Posts: 3,815
    edited 2007-03-05 16:51
    Because actually "708" is an ambiguous value when you begin talking "hexadecimal".

    If it's 708 Hex, then that's really 1800 Decimal.

    So, to reduce this confusion, compiler writers (for 'C', in this instance) create some way of designating if a value "literal" is decimal, hex, or binary.

    Thus, "708" decimal is the same value as "0x2C4", in 'C' language "literal"s.

    In PBasic, 16 decimal would be "$10" hexadecimal, or "%10000" binary.
Sign In or Register to comment.