Hexadecimal is closely related to binary numbers. There are 16 digits, or enough to hold 4 bits of information (or a half a byte, also called a nibble). Two hex numbers will represent a byte, or 8 bits.
The basic hex digits are: 0 1 2 3 4 5 6 7 8 9 A B C D E F then starting over with 10.
2 digits in Hex give you the numbers from 00 to FF in hex, the numbers from 0000 0000 to 1111 1111 in binary and the numbers 0 to 255 in decimal.
Let's start with a binary / Decimal / Octal / Hex table.
Binary Decimal Octal Hex 00 0000000000 00 0001010101 00 0010020202 00 0011030303 00 0100040404 00 0101050505 00 0110060606 00 0111070707 00 1000081008 00 1001091109 00 101010120A 00 101111130B 00 110012140C 00 110113150D 00 111014160E 00 111115170F 01 0000162010 01 0001172111 01 0010182212 01 0011192313 01 0100202414 01 0101212515 01 0110222616 01 0111232717 01 1000243018 01 1001253119 01 101026321A 01 101127331B 01 11002834
1C 01 110129351D 01 111030361E 01 111131371F 10 0000324020
Ok,
because the binary progresses on factors of 2, the octal and hex are easier to follow.
Any number ending in "7" in hex or octal will always end in "111" in binary.
Any number ending in "F" in hex will always end "1111" in binary.
Since Decimal doesn't use a base that is a power of 2, the numbers don't line up the same.
You can convert from Hex to Decimal by breaking out each digit and multiplying by the base.
Multiply the one's digit by 16^0 or 1
Multiply the tens digit by 16^1 or 16
Multiply the hundreds digit by 16^2 or 256
Multiply the thousands digit by 16^3 or 4096, etc.
And add them all up.
So, to convert: 3CF2 to decimal, you would:
Multiply 2*1 = 2
Multiply F (15) * 16 = 240
Multiply C (12) * 256 = 3072
Multiply 3 * 4096 = 12288
------------------
2 + 240 + 3072 + 12288 = 15602
Converting each digit to binary (using the table above if you want), you get:
0011 1100 1111 0010
To convert the other way, you keep dividing by 16, and keeping the "remainder" for the digit.
15602 / 16 = 975 r 2 --> 2
975 / 16 = 60 r 15 --> F
60 / 16 = 3 r 12 --> C
3 / 16 = 0 r 3 --> 3
Put it back together and you get the number above: 3CF2
Chat with our AI personalities