What is this encoding? 0x21
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.
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, 2022Comments
-
richard almost 2 years
I am reading about ASCII and the book said that
!
was represented as0x21
.Now I know that
!
is the binary00100001
in the ASCII table, which is also33
in decimal, which converted to hex is21
. But what is this0x
part of the encoding0x21
? -
richard almost 13 yearsWhy are they encoded into Hex? What would it be used for? Why not just use their binary or decimal values?
-
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 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 almost 13 yearsOther than these motivations, in reality often hex is used for constants for no other reason than being "cool" and
1337
:)