官术网_书友最值得收藏!

Converting between bases

We have already converted hexadecimal and binary numbers into decimal, or base-10. Converting base-10 into other bases simply requires division of the base being converted into, while taking note of the remainders.

The following is an example for base-2

87 to base-2

87 divided by 2 is 43 remainder 1.
43 divided by 2 is 21 remainder 1.
21 divided by 2 is 10 remainder 1.
10 divided by 2 is 5 remainder 0.
5 divided by 2 is 2 remainder 1.
2 divided by 2 is 1 remainder 0.
1 divided by 2 is 0 remainder 1.
and nothing more to divide since we're down to 0.

base-2 has digits 0 and 1.
Writing the remainders backward results to 1010111b.

The following is an example for base-16:

34512 to base-16

34512 divided by 16 is 2157 remainder 0.
2157 divided by 16 is 134 remainder 13 (0Dh)
134 divided by 16 is 8 remainder 6.
6 divided by 16 is 0 remainder 6.

base-16 has digits from 0 to 9 and A to F.
Writing the remainders backward results to 66D0h.

Converting from hexadecimal into binary simply requires knowing how many binary digits there are in a hexadecimal digit. The highest digit for a hexadecimal number is 0Fh (15) and is equivalent to 1111b. Take note that there are 4 binary digits in a hexadecimal digit. An example conversion is shown here:

ABCDh
0Ah = 1010b
0Bh = 1011b
0Ch = 1100b
0Dh = 1101b

Just combine the equivalent binary number.
ABCDh = 1010101111001101b

Split the binary number into four digits each when converting from binary into hexadecimal, as shown here:

1010010111010111b
1010b = 10 (0Ah)
0101b = 5
1101b = 13 (0Dh)
0111b = 7

1010010111010111b = A5D7h

So, why the use of base-2 and base-16 in computers, rather than our daily base-10 usage? Well, for base-2, there are two states: an on and an off signal. A state can easily be read and transmitted electronically. Base-16 compresses the representation of the binary equivalent of a decimal number. Take 10 for instance: this number is represented as 1010b and consumes 4 bits. To maximize the information that can be stored in 4 bits, we can represent numbers from 0 to 15 instead.

A 4-bit value is also called a nibble. It is half of a byte. Bytes can represent alphabets, numbers, and characters. This representation of characters is mapped in the ASCII table. The ASCII table has three sections: control, printable, and extended characters. There are 255 (FFh) ASCII characters. Lists of printable characters that can be typed on the keyboard and some of the extended characters with keyboard format can be found at https://github.com/PacktPublishing/Mastering-Reverse-Engineering/tree/master/ch3.

Though not directly visible from the English language keyboard, symbols can still be displayed by using the character's equivalent code.

主站蜘蛛池模板: 淮安市| 东莞市| 南郑县| 钟祥市| 临邑县| 江安县| 凭祥市| 仙居县| 都匀市| 措勤县| 同心县| 嘉禾县| 新巴尔虎右旗| 江川县| 南木林县| 乌鲁木齐市| 咸丰县| 泰顺县| 乌兰浩特市| 珲春市| 武宣县| 东乌| 井陉县| 汉川市| 团风县| 来安县| 岳阳市| 巴林左旗| 抚顺市| 耒阳市| 九江县| 万源市| 宣城市| 南和县| 天镇县| 那曲县| 昌乐县| 西乌珠穆沁旗| 山东省| 镇平县| 肥东县|