What is this encoding? 0x21

12,768

0x is the prefix used for hexadecimal numbers in almost every C-like programming language, so it has become the de-facto standard when writing hex numbers.

Sometimes you may also find hexadecimal numbers denoted by the h suffix (many assembly dialects follow this convention), or (in BASIC dialects) by the &H prefix.

Share:
12,768
richard
Author by

richard

I love this site. I am here to learn, and try to contribute back as much as possible. As an aside, I can't thank everyone on this site enough for their answers. This site (and it's sister sites through SE) are INVALUABLE.

Updated on June 04, 2022

Comments

  • richard
    richard almost 2 years

    I am reading about ASCII and the book said that ! was represented as 0x21.

    Now I know that ! is the binary 00100001 in the ASCII table, which is also 33 in decimal, which converted to hex is 21. But what is this 0x part of the encoding 0x21?

  • richard
    richard almost 13 years
    Why are they encoded into Hex? What would it be used for? Why not just use their binary or decimal values?
  • Matteo Italia
    Matteo Italia almost 13 years
    @Richard: hex is often used for values that have some particular significance in binary because hex is compact b the conversion from/to hex is straightforward. Also, groups of bits multiple of 4 stay in fixed length hex numbers (one "normal" byte is always two hex digits).
  • fyr
    fyr almost 13 years
    @Richard thats pretty easy developers are lazy. And numbers to the base of 16 are shorter than numbers to the base of 10 or 8 or 2 ... :) and they also can be easily translated to a binary string. Because every hex character can be translated to a 4 character binary respresentation.
  • Matteo Italia
    Matteo Italia almost 13 years
    Other than these motivations, in reality often hex is used for constants for no other reason than being "cool" and 1337 :)