Appendix
◾
639
to store 45102
8
in 16 bits, we would do the following: 4
=
100, 5
=
101, 1
=
001, 0
=
000,
2
=
010, so 45102
8
=
100 101 001 000 010
=
100101001000010
2
.
Since the five octal digits
is stored in 15 binary bits, we had to add a leading 0 to give us a total of 16 bits, giving us
0100101001000010
2
.
Let us try a few more for practice.
• Convert 00011100
2
to octal: 00 011 100, add a leading 0:000 011 100
=
0 3 4
=
034
8
.
• Convert 1111110010110111011
2
to octal: 1 111 110 010 110 111 011, add two leading 0s:
001 111 110 010 110 111 011
=
1 7 6 3 6 7 3
=
1763673
8
.
• Convert 4154
8
to 16 bit binary: 100 001 101 100, add 4 leading 0s: 0000100001101100
2
.
• Convert 260
8
to 8 bit binary: 010 110 000
=
010110000
2
. Notice that our answer is
really 9 bits. We drop the leading 0 to give us 10110000
2
. We have to be careful here,
had our octal number been 460
8
, we could not store it in 8 bits, this would cause an
overflow.
While octal is a useful representation to reduce the quantity of digits when represent-
ing data in binary, we could reduce the digits
even further using hexadecimal, or base 16.
Recall from Section A.1 that a base
k
numbering system uses digits 0 through
k
−
1. In
binary,
k
is 2 and we use digits 0 and 1. In octal,
k
is 8 and we use 0 through 7. In hexadeci-
mal,
k
is 16. This implies that we use 0 through 15.
Our numbering system requires that each digit be expressed
in a single column of the
number. That is, each digit needs to be specified using a single character. What should we
do about 10, 11, 12, 13, 14, and 15 for hexadecimal? We need to represent these multidigit
values using single digits. Instead of trying to use a digit, we replace each with a single
character. In this case, we will use the first six letters, A, B, C, D, E, F. For instance, the
number 11 would be represented as B in hexadecimal and 14 would
be represented as E in
hexadecimal.
Notice that 16 is twice 8, so there are twice as many possible combinations needed to
store a single hexadecimal over that of a single octal digit. By doubling the number of com-
binations, we need an additional bit of storage. Why? Consider in 3 bits we store values of
000 to 111 (0 to 7, or eight total values). By adding a bit, we now store _000 to _111 where
the blank can be a 0 or a 1. So this gives us 0000 to 0111 and 1000 to 1111. Thus,
increasing
the storage capacity by 1 bit doubles the number of sequences.
The 4-bit binary values are shown in Table A.5 along with their equivalent decimal val-
ues and hexadecimal values. In looking at the 4-bit numbers, you might think of them as 0
followed by the 3-bit binary numbers and 1 followed by the 3-bit binary numbers of Table
A.4. In this table, note that in place of single digits for the values 10 through 15, we use the
letters A through F to represent the last 6 hexadecimal values.
To convert from binary to hexadecimal, use the same
approach as converting from
binary to octal but group the binary bits into sets of four bits instead of three. Add leading
zeroes to the leftmost group as needed. To convert from hexadecimal to binary, convert
640
◾
Appendix
each hexadecimal digit to its equivalent 4-bit binary value. Add leading 0s as needed to fill
up the storage size. Below we have several examples.
• 10111011111101
2
: 10 1110 1111 1101, add 2 leading 0s
=
0010 1110 1111 1101
=
2 E F
D
=
2EFD
16
• 1011000000010
2
: 1 0110 0000 0010, add 3 leading 0s
=
0001 0110 0000 0010
=
16 0
2
=
1602
16
• A3B4
16
=
1010 0011 1011 0100
=
1010001110110100
2
• 123F
16
=
0001 0010 0011 1111
=
01001000111111
2
Four hexadecimal digits convert to exactly 16 binary bits.
Converting between hexa-
decimal and binary is somewhat simpler than between octal and binary because we often
will not need to add leading bits.
A.4 STORAGE CAPACITIES
While we are exploring binary, we should consider the amount of information we can store
using a binary representation.
The term
storage capacity
conveys the size of the informa-
tion that can be placed into/onto a storage device. When we hear about gigabytes of main
memory or terabytes for disk storage, it sounds impressive. But what do these values really
mean?
We will start off at the most primitive unit of storage, the
bit
. One bit stores a single
binary digit and as we saw in Section A.1, a binary digit stores either a 0 or a 1. Thus, a
bit stores one of two possible values. We can confirm this because in 1 bit, we have 2
1
TABLE A.5
Decimal, Binary, and Hexadecimal for First 16
Numbers
Do'stlaringiz bilan baham: