Binary & Hexadecimal Number Systems

 
   

Decimal Numbers   Our normal number system uses place notation. The value of each digit is determined by two things: the digit itself, and where it is (its place) within the number. Because we use ten different digits (0 through 9), this system is called base-10, or decimal. Each place represents a different power of ten. Let’s use the number 8653 as an example.

8653

From right to left,

the 3 is in the 100 (ones) place. There are 3 ones, or 3.
the 5 is in the 101 (tens) place. There are 5 tens, or 50.
the 6 is in the 10² (hundreds) place. There are 6 hundreds, or 600.
the 8 is in the 10³ (thousands) place. There are 8 thousands, or 8000.

Added all together, these give 8000 + 600 + 50 +3 = 8653.

Why 10? Presumably because we have ten fingers, most human languages developed number systems based on the number ten. In fact, our word ‘digit’ comes from the Latin word digitus, meaning ‘finger’. But really, there’s nothing magical about the number ten, and any other number could serve as the basis of a place-value number system. The Mayans used a base-20 system, and the Babylonians had a base-60 system.

Activities & Practice
to do as you read

 

 

 

 

 

1. What is the digit in the 104 place in the number 956,340? What is the digit in the 10² place?

Analog and Digital   In electronic computers, numbers need to be represented by voltages on wires. One way to do this is to have the number be proportional to the voltage. For example, for a scale of 1 Volt representing 1000, 2 Volts would represent 2000, and 8.653 Volts would represent the number 8653. Computers based on such systems are called analog computers, and there have been many analog computers built and used. There is an inherent flaw, though, with analog computers. Within any electronic circuit there is so-called noise, seemingly random voltage variations caused by the thermal motion of atoms in the wires and the voltages picked up by any wire from the electromagnetic fields radiated by other nearby wires (crosstalk).

This noise is usually small --- a few tenths of a volt is typical, so it doesn’t make any difference in the power cord running a TV or blender, for instance. But in an analog computer, any noise would change the values of the numbers represented by those voltages --- bad news. Analog computers, therefore, have to be very carefully designed and built to minimize the effects of noise.

A way to avoid the problems of analog computers is to have the voltages represent digits, rather than the numbers themselves. That's where the word ‘digital’ comes from. You could, for example, have the digit 0 represented by 0 Volts, 1 by 1 Volt, 2 by 2 Volts, and so forth, up to 9 Volts. The number 8653 then would be represented by four wires, carrying 8V, 6V, 5V, and 3V (this is called parallel) or perhaps instead by a single wire whose voltage changes from 8V to 6V to 5V then 3V (this is called serial). Any voltage near 5V would be interpreted as the digit ‘5’: 4.93V, 5.27V, 4.61V, 5.32V would all be ‘5’, eliminating the effects of noise, assuming the noise is less than 0.5V. Noise and crosstalk would have to get really bad before the data get corrupted.

The fewer the digits, the less susceptible the system is to noise. This argues for having a system with only two digits, a binary system. Also, it is simpler to build circuits that respond to only two states, rather than ten. So, almost all digital computers use voltages to represent only two digits, 0 and 1.


 

Binary Numbers   A number system using only two numerals, 0 and 1, is called binary, or base-2. Rather than calling the ones and zeros ‘digits’ (which, as mentioned above, comes from the Latin word for ‘finger’, sort of implying there are ten) the phrase ‘binary digit’ was often used, and then that got shortened to ‘bit’.

In a binary number, each place is a different power of two. As an example, let’s look at the binary number 1101.
       1101
From right to left,  

there is a 1 in the 20 (ones) place. There is one one = 1
there is a 0 in the 21 (twos) place. There are no twos = 0
there is a 1 in the 2² (fours) place. There is one four = 4
there is a 1 in the 2³ (eights) place. There is one eight = 8.

Added all together, that gives us 8+4+0+1 or 13 (written in decimal).

You can see that four bits (which is called a nibble, by the way) can represent, at most, the number 15. A byte is a group of 8 bits, which can represent any integer from 0 to 255. In general, a group of n bits can represent integers from 0 up to 2n-1.

Let’s look at a longer example, a word (defined as 16 bits, or 2 bytes).

0010000111001101

From right to left,

there is a 1 in the 20 (ones) place. There is one one = 1
there is a 0 in the 21 (twos) place. There are no twos = 0
there is a 1 in the 2² (fours) place. There is one four = 4
there is a 1 in the 23 (eights) place. There is one eight = 8
there are 0’s in the 24 (sixteens) and 25 (32s) places = 0
there is a 1 in the 26 (64s) place. There is one 64 = 64
there is a 1 in the 27 (128s) place. There is one 128 = 128
there is a 1 in the 28 (256s) place. There is one 256 = 256
there are 0’s in the 29 (512s), 210 (1024s), 211 (2048s) and 212 (4096s) places
there is a 1 in the 213 (8192s) place. There is one 8192 = 8192

Adding all these up gives us 8192 + 256 + 128 + 64 + 8 + 4 + 1 = 8653 in decimal.

 


 

 

 

 

 

 

2. What is the decimal equivalent of the following binary numbers?

(a) 1001
(b) 1111
(c) 0101
(d) 1011

3. What is the bit in the 2² place in each of the above binary numbers?

4. In the binary number 110111111, what place is the 0 in?

5. Write the decimal values of the powers of 2, from 20 up to and including 216.

6. Write the following decimal numbers in binary.
(a) 14 (b) 7 (c) 19 (d) 33

7. What is the decimal equivalent of each of these binary numbers?

(a) 11111111
(b) 10101010
(c) 11110000
(d) 00110010

Distinguishing Numbers Written In Different Bases   When you see the number 1101, how do you know that is a binary number representing the decimal number thirteen, or the decimal number one thousand one hundred and one? Often it’s clear from the context of the discussion, but it’s handy to have a simple way to distinguish. From now on, if there's any possibility of confusion, we’ll end every binary number with a ‘b’, and every decimal number with a ‘d’.

1101b = the binary representation of the decimal number thirteen
1101d = the decimal number one thousand one hundred and one

 

 

Hexadecimal numbers   As you saw from the example above, base-2 numbers require a lot of bits to represent any large quantity. For 8653d, we needed 14 bits --- we used a word (16 bits) but the first two leading bits were zeros. With so many 0’s and 1’s, it’s just confusing.

It would be a lot easier to split the bits into groups of four (that is, into nibbles). Each nibble can represent a number from 0 to 15, and these can be represented by the digits 0 to 9, plus the letters A through F. In other words, we’re constructing a base-16, or hexadecimal, number system. We’ll use an ‘h’ at the end of a number to indicate that it is a hexadecimal number.

0000b = 0d = 0h
0001b = 1d = 1h
0010b = 2d = 2h
0011b = 3d = 3h
0100b = 4d = 4h
0101b = 5d = 5h
0110b = 6d = 6h
0111b = 7d = 7h
1000b = 8d = 8h
1001b = 9d = 9h
1010b = 10d = Ah
1011b = 11d = Bh
1100b = 12d = Ch
1101b = 13d = Dh
1110b = 14d = Eh
1111b = 15d = Fh

Let's look at our previous binary example:

0010 0001 1100 1101 binary (this is the same number we used above, only broken into 4-bit chunks)
   2       1       C       D hexadecimal

Let's look at the place-values in hexadecimal.

21CDh
there is a D in the 160 (ones) place = 13 in decimal
there is a C in the 161 (sixteens) place = 12 x 16 = 192 in decimal
there is a 1 in the 16² (256s) place = 256
there is a 2 in the 16³ (4096s) place = 8192

adding these up gives us 8192 + 256 + 192 + 13 = 8653d

 

 

 

 

 

8. Write these binary numbers in hexadecimal.

(a) 11111111
(b) 10101010
(c) 11110000
(d) 00110010

9. Write these hex numbers in binary.

(a) F0F0
(b) 1234
(c) ABCD
(d) C3B0

 

10. Write these hex numbers in decimal.

(a) F0F0
(b) 1234
(c) ABCD
(d) C3B0

11. Explain this amusing quote: "There are 10 kinds of people in the world - those who know binary and those who don't."

ANSWERS



 

 

 

HTML Comment Box is loading comments...