Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Programming
Comparison of Representations
System Digits
Binary (Base 2): 0, 1
Octal (Base 8): 0, 1, 2, 3, 4, 5, 6, 7
Decimal (Base 10): 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
Hexadecimal (Base 16): 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F
0 00 0000 0000 0
1 01 0000 0001 1
2 02 0000 0010 2
3 03 0000 0011 3
4 04 0000 0100 4
5 05 0000 0101 5
6 06 0000 0110 6
7 07 0000 0111 7
8 08 0000 1000 10
9 09 0000 1001 11
10 0A 0000 1010 12
11 0B 0000 1011 13
12 0C 0000 1100 14
13 0D 0000 1101 15
14 0E 0000 1110 16
15 0F 0000 1111 17
1 of 4 31/10/2009 10:46 PM
Converting Between Integer Representations -- Technical Notes http://academic.evergreen.edu/projects/biophysics/technotes/program/in...
16 10 0001 0000 20
17 11 0001 0001 21
18 12 0001 0010 22
A binary, a hexadecimal or an octal number can be expressed as the sum of the successive powers of the bas
2, 16, or 8, respectively), with the coefficients being the digits.
For example,
To convert a decimal number into a binary number, divide it by 2 repeatedly and note the remainders. The
remainders are the bits of the binary number. The last remainder is the most significant bit, and the first rem
the least significant bit.
For example,
13(base 10) = 1101(base 2) 13 ÷ 2 = 6 remainder 1 LSB
6 ÷ 2 = 3 remainder 0
3 ÷ 2 = 1 remainder 1
1 ÷ 2 = 0 remainder 1 MSB
2 of 4 31/10/2009 10:46 PM
Converting Between Integer Representations -- Technical Notes http://academic.evergreen.edu/projects/biophysics/technotes/program/in...
There are two different ways to convert a decimal number into a hexadecimal number.
1. The first method is similar to converting a decimal to a binary and involves dividing the number by decim
and noting the remainders. The first remainder is the least significant digit and the last remainder is the most
significant digit.
For example,
4620(base 10) = 120C(base 16) 4620 ÷ 16 = 288 remainder 12 = C LSB
288 ÷ 16 = 18 remainder 0
18 ÷ 16 = 1 remainder 2
1 ÷ 16 = 0 remainder 1 MSB
2. The second method involves converting the decimal number into a binary, then convert the binary in
hexadecimal number. To change the representation of the binary number to hexadecimal, separate the digits
4-bit groups beginning with the least significant bit. Then write the hexadecimal equivalent of each group.
For example,
23(base 10) = 17(base 16)
1 7 (base 16)
To convert a decimal number into an octal number, divide it by 8 repeatedly and note the remainders. The
remainders are the digits of the octal number. The last remainder is the most significant digit, and the first re
is the least significant digit.
For example,
1701(base 10) = 3245(base 8) 1701 ÷ 8 = 212 remainder 5 LSB
212 ÷ 8 = 26 remainder 4
26 ÷ 8 = 3 remainder 2
3 ÷ 8 = 0 remainder 3 MSB
3 of 4 31/10/2009 10:46 PM
Converting Between Integer Representations -- Technical Notes http://academic.evergreen.edu/projects/biophysics/technotes/program/in...
From Binary to Hexadecimal: To convert a binary number into its hexadecimal form, start by grouping th
into 4-bit groups. Beginning with the least significant bit (all the way to the right of the number), write the
hexadecimal equivalent of each group.
For example,
9 F 6 5 (base 16)
MSB LSB
From Hexadecimal to Binary: To convert a hexadecimal number into a binary, just reverse the above proc
starting all the way to the right, convert each digit into a 4-bit binary number.
From Binary to Octal: To convert a binary number into its octal form, start by grouping the digits into 3-bi
Beginning with the least significant bit (all the way to the right of the number), write the octal equivalent of
group.
For example,
2 6 7 3 (base 8)
MSB LSB
From Octal to Binary: To convert an octal number into a binary, just reverse the above process; starting a
way to the right, convert each digit into a 3-bit binary number.
DISCLAIMER
4 of 4 31/10/2009 10:46 PM