0% found this document useful (0 votes)
17 views10 pages

Binary Octal and Hexadecimal Numbers

Chapter 10 discusses the importance of understanding binary, octal, and hexadecimal number systems in relation to digital circuits and computing. It explains how these systems facilitate easier communication between humans and computers, which primarily operate in binary. The chapter also covers conversion methods between these number systems and provides practice exercises for better comprehension.

Uploaded by

susmitsaha123456
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views10 pages

Binary Octal and Hexadecimal Numbers

Chapter 10 discusses the importance of understanding binary, octal, and hexadecimal number systems in relation to digital circuits and computing. It explains how these systems facilitate easier communication between humans and computers, which primarily operate in binary. The chapter also covers conversion methods between these number systems and provides practice exercises for better comprehension.

Uploaded by

susmitsaha123456
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Chapter 10

Binary, octal and


hexadecimal numbers
Why it is important to understand: Binary, octal and hexadecimal numbers
There are infinite ways to represent a number. The four commonly associated with modern computers
and digital electronics are decimal, binary, octal, and hexadecimal. All four number systems are equally
capable of representing any number. Furthermore, a number can be perfectly converted between the
various number systems without any loss of numeric value. At first look, it seems like using any number
system other than decimal is complicated and unnecessary. However, since the job of electrical and
software engineers is to work with digital circuits, engineers require number systems that can best transfer
information between the human world and the digital circuit world. Thus the way in which a number is
represented can make it easier for the engineer to perceive the meaning of the number as it applies to
a digital circuit, i.e. the appropriate number system can actually make things less complicated. Binary,
octal and hexadecimal numbers are explained in this chapter.

At the end of this chapter, you should be able to:

• recognise a binary number


• convert binary to decimal and vice-versa
• add binary numbers
• recognise an octal number
• convert decimal to binary via octal and vice-versa
• recognise a hexadecimal number
• convert from hexadecimal to decimal and vice-versa
• convert from binary to hexadecimal and vice-versa

trade, time, distance, and all other phases of human


10.1 Introduction life. Ever since people discovered that it was nec-
essary to count objects, they have been looking for
Man’s earliest number or counting system was prob-
easier ways to do so. The abacus, developed by
ably developed to help determine how many pos-
the Chinese, is one of the earliest known calcula-
sessions a person had. As daily activities became
tors; it is still in use in some parts of the world.
more complex, numbers became more important in

Higher Engineering Mathematics. 978-1-138-67357-1, © 2017 John Bird. Published by Taylor & Francis. All rights reserved.
Binary, octal and hexadecimal numbers 91

Blaise Pascal∗ invented the first adding machine in of enemy targets. The advantages of digital comput-

Section A
1642. Twenty years later, an Englishman, Sir Samuel ers include speed, accuracy, and man-power savings.
Morland∗ , developed a more compact device that could Often computers are able to take over routine jobs and
multiply, add, and subtract. About 1672, Gottfried Wil- release personnel for more important work that can-
helm von Leibniz∗ perfected a machine that could not be handled by a computer. People and computers
perform all the basic operations (add, subtract, multi- do not normally speak the same language. Methods of
ply, divide), as well as extract the square root. Modern translating information into forms that are understand-
electronic digital computers still use von Leibniz’s able and usable to both are necessary. Humans generally
principles. speak in words and numbers expressed in the decimal
Computers are now employed wherever repeated number system, while computers only understand coded
calculations or the processing of huge amounts of data electronic pulses that represent digital information.
are needed. The greatest applications are found in the All data in modern computers is stored as series of
military, scientific, and commercial fields. They have bits, a bit being a binary digit, and can have one of
applications that range from mail sorting, and engi- two values, the numbers 0 and 1. The most basic form
neering design, to the identification and destruction of representing computer data is to represent a piece of
data as a string of 1s and 0s, one for each bit. This is
called a binary or base-2 number.
Because binary notation requires so many bits to rep-
resent relatively small numbers, two further compact
notations are often used, called octal and hexadeci-
mal. Computer programmers who design sequences of
number codes instructing a computer what to do would
have a very difficult task if they were forced to work
with nothing but long strings of 1s and 0s, the ‘native
language’ of any digital circuit.
Octal notation represents data as base-8 numbers with
each digit in an octal number representing three bits.
Similarly, hexadecimal notation uses base-16 numbers,
representing four bits with each digit. Octal numbers
use only the digits 0–7, while hexadecimal numbers
use all ten base-10 digits (0–9) and the letters A–F
(representing the numbers 10–15).
This chapter explains how to convert between the
decimal, binary, octal and hexadecimal systems.

10.2 Binary numbers


The system of numbers in everyday use is the denary
or decimal system of numbers, using the digits 0 to 9.
∗ Who was Leibniz? Gottfried Wilhelm Leibniz (sometimes
It has ten different digits (0, 1, 2, 3, 4, 5, 6, 7, 8 and 9)
von Leibniz theorem∗ ) (1 July 1646–14 November 1716) was and is said to have a radix or base of 10.
a German mathematician and philosopher. Leibniz developed The binary system of numbers has a radix of 2 and uses
infinitesimal calculus and invented the Leibniz wheel. To find only the digits 0 and 1.
out more go to www.routledge.com/cw/bird
∗ Who was Morland? Sir Samuel Morland, 1st Baronet
(a) Conversion of binary to decimal
(1625–1695), was an English academic, diplomat, spy, inven- The decimal number 234.5 is equivalent to
tor and mathematician of the 17th century, a polymath
credited with early developments in relation to comput-
ing, hydraulics and steam power. To find out more go to 2 × 102 + 3 × 101 + 4 × 100 + 5 × 10−1
www.routledge.com/cw/bird
∗ Who was Pascal? For image and resume of Pascal, see i.e. the sum of terms comprising: (a digit) multiplied by
page 59. To find out more go to www.routledge.com/cw/bird (the base raised to some power).
92 Higher Engineering Mathematics

In the binary system of numbers, the base is 2, so 1101.1


Section A

is equivalent to: 3. (a) 101010 (b) 111000 (c) 1000001


(d) 10111000
1 × 23 + 1 × 22 + 0 × 21 + 1 × 20 + 1 × 2−1
4. (a) 0.1101 (b) 0.11001 (c) 0.00111
Thus the decimal number equivalent to the binary (d) 0.01011
number 1101.1 is 8 + 4 + 0 +1 + 12 , that is 13.5 i.e.
1101.1 2 = 13.510 , the suffixes 2 and 10 denoting binary 5. (a) 11010.11 (b) 10111.011 (c) 110101.0111
and decimal systems of numbers respectively. (d) 11010101.10111

Problem 1. Convert 11011 2 to a decimal number.


(b) Conversion of decimal to binary
4 3 2
From above: 11011 2 = 1 × 2 + 1 × 2 + 0 × 2 An integer decimal number can be converted to a cor-
1
+1×2 +1×2 0 responding binary number by repeatedly dividing by 2
and noting the remainder at each stage, as shown below
= 16 + 8 + 0 + 2 + 1 for 3910 .
= 2710
2 39 Remainder
Problem 2. Convert 0.1011 2 to a decimal 2 19 1
fraction. 2 9 1
2 4 1
0.10112 = 1 × 2−1 + 0 × 2−2 + 1 × 2−3 + 1 ×2−4 2 2 0
2 1 0
1 1 1 1
= 1× + 0× 2 + 1× 3 + 1× 4 0 1
2 2 2 2
1 1 1 1 0 0 1 1 1
= + +
2 8 16 (most significant bit) (least significant bit)
= 0.5 + 0.125 + 0.0625
The result is obtained by writing the top digit of the
= 0.6875 10
remainder as the least significant bit (a bit is a binary
Problem 3. Convert 101.0101 2 to a decimal digit and the least significant bit is the one on the right).
number. The bottom bit of the remainder is the most significant
bit, i.e. the bit on the left.
Thus 3910 = 100111 2
101.0101 2 = 1 × 22 + 0 ×21 + 1 × 20 + 0 ×2−1
The fractional part of a decimal number can be converted
+ 1 ×2−2 + 0 × 2−3 + 1 × 2−4 to a binary number by repeatedly multiplying by 2, as
shown below for the fraction 0.625
= 4 + 0 + 1 + 0 + 0.25 + 0 + 0.0625
0.625 3 2 5 1. 250
= 5.312510
0.250 3 2 5 0. 500
Now try the following Practice Exercise
0.500 3 2 5 1. 000

Practice Exercise 39 Conversion of binary (most significant bit) .1 0 1 (least significant bit)
to decimal numbers (Answers on page 859)
For fractions, the most significant bit of the result is the
In Problems 1 to 5, convert the binary numbers top bit obtained from the integer part of multiplication
given to decimal numbers. by 2. The least significant bit of the result is the bottom
bit obtained from the integer part of multiplication by 2.
1. (a) 110 (b) 1011 (c) 1110 (d) 1001
Thus 0.625 10 = 0.1012
2. (a) 10101 (b) 11001 (c) 101101 (d) 110011
Binary, octal and hexadecimal numbers 93

The fractional part is repeatedly multiplied by 2 giving:


Problem 4. Convert 47 10 to a binary number.

Section A
0.3125 3 2 5 0.625
From above, repeatedly dividing by 2 and noting the 0.625 3 2 5 1.25
remainder gives: 0.25 3 2 5 0.5
0.5 325 1.0
2 47 Remainder
.0 1 0 1
2 23 1
2 11 1 Thus 58.3125 10 = 111010.0101 2
2 5 1
Now try the following Practice Exercise
2 2 1
2 1 0
Practice Exercise 40 Conversion of
0 1
decimal to binary numbers (Answers on
1 0 1 1 1 1 page 860)
Thus 4710 = 101111 2 In Problems 1 to 5, convert the decimal numbers
given to binary numbers.
1. (a) 5 (b) 15 (c) 19 (d) 29
Problem 5. Convert 0.40625 10 to a binary
number. 2. (a) 31 (b) 42 (c) 57 (d) 63
3. (a) 47 (b) 60 (c) 73 (d) 84
From above, repeatedly multiplying by 2 gives:
4. (a) 0.25 (b) 0.21875 (c) 0.28125
0.40625 3 2 5 0. 8125 (d) 0.59375

0.8125 325 1. 625


5. (a) 47.40625 (b) 30.8125 (c) 53.90625
(d) 61.65625
0.625 325 1. 25
(c) Binary addition
0.25 325 0. 5
Binary addition of two/three bits is achieved according
to the following rules:
0.5 325 1. 0
sum carry sum carry
.0 1 1 0 1 0+0= 0 0 0+0+0 = 0 0
0+1= 1 0 0+0+1 = 1 0
i.e. 0.40625 10 = 0.01101 2 1+0= 1 0 0+1+0= 1 0
1+1= 0 1 0+1+1= 0 1
1+0+0 = 1 0
Problem 6. Convert 58.3125 10 to a binary
1+0+1 = 0 1
number.
1+1+0= 0 1
1+1+1= 1 1
The integer part is repeatedly divided by 2, giving: These rules are demonstrated in the following worked
2 58 Remainder problems.
2 29 0
2 14 1 Problem 7. Perform the binary addition:
2 7 0 1001 + 10110
2 3 1
1001
2 1 1 +10110
0 1 11111
1 1 1 0 1 0
94 Higher Engineering Mathematics

Problem 8. Perform the binary addition:


Section A

10.3 Octal numbers


11111 + 10101
For decimal integers containing several digits, repeat-
edly dividing by 2 can be a lengthy process. In this case,
11111
+10101 it is usually easier to convert a decimal number to a
sum 110100 binary number via the octal system of numbers. This
carry 11111 system has a radix of 8, using the digits 0, 1, 2, 3, 4,
5, 6 and 7. The decimal number equivalent to the octal
number 4317 8 is:
Problem 9. Perform the binary addition:
4 × 83 + 3 × 82 + 1 × 81 + 7 × 80
1101001 + 1110101
i.e. 4 × 512 + 3 × 64 + 1 × 8 + 7 × 1 or 2255 10
1101001 An integer decimal number can be converted to a cor-
+1110101
sum 11011110 responding octal number by repeatedly dividing by 8
carry 11 1 and noting the remainder at each stage, as shown below
for 493 10
Problem 10. Perform the binary addition: 8 493 Remainder
1011101 + 1100001 + 110101 8 61 5
8 7 5
1011101 0 7
1100001
+ 110101 7 5 5
sum 11110011
carry 11111 1
Thus 49310 = 7558
The fractional part of a decimal number can be converted
to an octal number by repeatedly multiplying by 8, as
Now try the following Practice Exercise
shown below for the fraction 0.4375 10
0.4375 3 8 5 3. 5
Practice Exercise 41 Binary addition
(Answers on page 860)
0.5 385 4. 0
Perform the following binary additions:
1. 10 + 11 .3 4
2. 101 + 110
For fractions, the most significant bit is the top integer
3. 1101 + 111 obtained by multiplication of the decimal fraction by
4. 1111 + 11101 8, thus,
0.437510 = 0.348
5. 110111 + 10001
The natural binary code for digits 0 to 7 is shown
6. 10000101 + 10000101 in Table 10.1, and an octal number can be converted
7. 11101100 + 111001011 to a binary number by writing down the three bits
corresponding to the octal digit.
8. 110011010 + 11100011
9. 10110 + 1011 + 11011 Thus 4378 = 100 011 111 2

10. 111 + 10101 + 11011 and 26.35 8 = 010 110.011 101 2


11. 1101 + 1001 + 11101 The ‘0’ on the extreme left does not signify anything,
12. 100011 + 11101 + 101110 thus 26.35 8 = 10 110.011 101 2
Conversion of decimal to binary via octal is demon-
strated in the following worked problems.
Binary, octal and hexadecimal numbers 95

Table 10.1
Problem 13. Convert 5613.90625 10 to a binary

Section A
Octal digit Natural number, via octal.
binary number
The integer part is repeatedly divided by 8, noting the
0 000
remainder, giving:
1 001
8 5613 Remainder
2 010 8 701 5
3 011 8 87 5
8 10 7
4 100 8 1 2
5 101 0 1

6 110 1 2 7 5 5

7 111 This octal number is converted to a binary number,


(see Table 10.1).

Problem 11. Convert 3714 10 to a binary number, 127558 = 001 010 111 101 101 2
via octal. i.e. 561310 = 1 010 111 101 101 2
Dividing repeatedly by 8, and noting the remainder The fractional part is repeatedly multiplied by 8, and
gives: noting the integer part, giving:
8 3714 Remainder
8 464 2 0.90625 3 8 5 7.25
0.25 385 2.00
8 58 0
8 7 2 .7 2
0 7
This octal fraction is converted to a binary number,
7 2 0 2 (see Table 10.1).

From Table 10.1, 7202 8 = 111 010 000 010 2 0.728 = 0.111 010 2
i.e. 3714 10 = 111 010 000 010 2 i.e. 0.90625 10 = 0.111 01 2

Thus, 5613.90625 10 = 1 010 111 101 101.111 01 2


Problem 12. Convert 0.59375 10 to a binary
number, via octal.
Problem 14. Convert 11 110 011.100 01 2 to a
decimal number via octal.
Multiplying repeatedly by 8, and noting the integer
values, gives:
Grouping the binary number in three’s from the binary
0.59375 3 8 5 4.75
point gives: 011 110 011.100 010 2
0.75 385 6.00 Using Table 10.1 to convert this binary number to an
octal number gives 363.42 8 and 363.42 8
.4 6
= 3 × 82 + 6 × 81 + 3 × 80 + 4 × 8−1 + 2 × 8−2
Thus 0.59375 10 = 0.468
= 192 + 48 + 3 + 0.5 + 0.03125
From Table 10.1, 0.46 8 = 0.100 110 2
i.e. 0.59375 10 = 0.100 11 2 = 243.53125 10
96 Higher Engineering Mathematics

Now try the following Practice Exercise


Section A

and 1BF16 = 1 × 162 + B × 161 + F × 160


Practice Exercise 42 Conversion between = 1 × 162 + 11 × 161 + 15 × 160
decimal and binary numbers via octal
(Answers on page 860) = 256 + 176 + 15 = 447 10

In Problems 1 to 3, convert the decimal numbers Table 10.2 compares decimal, binary, octal and hexa-
given to binary numbers, via octal. decimal numbers and shows, for example, that
2310 = 101112 = 278 = 1716
1. (a) 343 (b) 572 (c) 1265
2. (a) 0.46875 (b) 0.6875 (c) 0.71875 Problem 15. Convert the following hexadecimal
numbers into their decimal equivalents:
3. (a) 247.09375 (b) 514.4375 (c) 1716.78125 (a) 7A16 (b) 3F16
4. Convert the binary numbers given to decimal
numbers via octal. (a) 7A16 = 7 × 161 + A × 160 = 7 × 16 + 10 × 1
(a) 111.011 1 (b) 101 001.01
(c) 1 110 011 011 010.001 1 = 112 + 10 = 122
Thus 7A16 = 12210
(b) 3F16 = 3 × 161 + F × 160 = 3 × 16 + 15 × 1
10.4 Hexadecimal numbers
= 48 + 15 = 63
The hexadecimal system is particularly important in
computer programming, since four bits (each consist- Thus 3F16 = 6310
ing of a one or zero) can be succinctly expressed using
a single hexadecimal digit. Two hexadecimal digits rep- Problem 16. Convert the following hexadecimal
resent numbers from 0 to 255, a common range used, numbers into their decimal equivalents:
for example, to specify colours. Thus, in the HTML (a) C916 (b) BD16
language of the web, colours are specified using three
pairs of hexadecimal digits RRGGBB, where RR is the (a) C916 = C × 161 + 9 × 160 = 12 × 16 + 9 × 1
amount of red, GG the amount of green, and BB the
amount of blue. = 192 + 9 = 201
A hexadecimal numbering system has a radix of
16 and uses the following 16 distinct digits: Thus C916 = 20110

0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E and F (b) BD16 = B × 161 + D × 160

‘A’ corresponds to 10 in the decimal system, B to 11, = 11 × 16 + 13 × 1 = 176 + 13 = 189


C to 12, and so on.
Thus BD16 = 18910
(a) Converting from hexadecimal to decimal
Problem 17. Convert 1A4E 16 into a decimal
For example number.
1A16 = 1 × 161 + A × 160
= 1 × 161 + 10 × 1 1A4E16 = 1 × 163 + A × 162 + 4 × 161 + E × 160
= 16 + 10 = 26 = 1 × 163 + 10 × 162 + 4 × 161 + 14 × 160
i.e. 1A16 = 2610 = 1 × 4096 + 10 × 256 + 4 × 16 + 14× 1
Similarly, 2E16 = 2 × 161 + E × 160 = 4096 + 2560 + 64 + 14 = 6734
= 2 × 161 + 14 × 160
Thus 1A4E16 = 673410
= 32 + 14 = 46 10
Binary, octal and hexadecimal numbers 97

Table 10.2 (b) Converting from decimal to hexadecimal

Section A
Decimal Binary Octal Hexadecimal
This is achieved by repeatedly dividing by 16 and noting
0 0000 0 0 the remainder at each stage, as shown below for 26 10
1 0001 1 1
16 26 Remainder
2 0010 2 2 16 1 10 ; A16
3 0011 3 3 0 1 ; 116

4 0100 4 4 most significant bit 1 A least significant bit


5 0101 5 5
Hence 2610 = 1A16
6 0110 6 6
7 0111 7 7 Similarly, for 447 10
8 1000 10 8
9 1001 11 9 16 447 Remainder
16 27 15 ; F16
10 1010 12 A
16 1 11 ; B16
11 1011 13 B 0 1 ; 116
12 1100 14 C 1 B F
13 1101 15 D
Thus 44710 = 1BF16
14 1110 16 E
15 1111 17 F Problem 18. Convert the following decimal
numbers into their hexadecimal equivalents:
16 10000 20 10
(a) 3710 (b) 108 10
17 10001 21 11
18 10010 22 12 (a) 16 37 Remainder
19 10011 23 13 16 2 5 5 516
0 2 5 216
20 10100 24 14
2 5
21 10101 25 15
most significant bit least significant bit
22 10110 26 16
23 10111 27 17 Hence 3710 = 2516
24 11000 30 18
(b) 16 108 Remainder
25 11001 31 19
16 6 12 5 C16
26 11010 32 1A 0 6 5 616
27 11011 33 1B 6 C
28 11100 34 1C
Hence 10810 = 6C16
29 11101 35 1D
30 11110 36 1E Problem 19. Convert the following decimal
31 11111 37 1F numbers into their hexadecimal equivalents:
(a) 16210 (b) 239 10
32 100000 40 20
98 Higher Engineering Mathematics

(a) 16 162 Remainder to each group gives as above, from Table 10.2.
Section A

16 10 2 5 216
Thus, 11010110 2 = D616
0 10 5 A16
A 2 (b) Grouping bits in fours from the right gives:
   0111
0110    and assigning hexadecimal symbols
Hence 16210 = A216 6 7
to each group gives as above, from Table 10.2.
(b) 16 239 Remainder Thus, 1100111 2 = 6716
16 14 15 5 F16
0 14 5 E16 Problem 21. Convert the following binary
E F numbers into their hexadecimal equivalents:
(a) 11001111 2 (b) 110011110 2
Hence 23910 = EF16
(a) Grouping bits in fours from the right gives:
Now try the following Practice Exercise 1100
   1111
   and assigning hexadecimal symbols
C F
to each group gives as above, from Table 10.2.
Practice Exercise 43 Hexadecimal
numbers (Answers on page 860) Thus, 11001111 2 = CF16
(b) Grouping bits in fours from the right gives:
In Problems 1 to 4, convert the given hexadecimal    1001
0001    1110
   and assigning hexadecimal
numbers into their decimal equivalents. 1 9 E
symbols to each group gives as above, from
1. E716 2. 2C16
Table 10.2.
3. 9816 4. 2F116
Thus, 110011110 2 = 19E16
In Problems 5 to 8, convert the given decimal
numbers into their hexadecimal equivalents.
(d) Converting from hexadecimal to binary
5. 5410 6. 20010
The above procedure is reversed; thus, for example,
7. 9110 8. 23810
6CF316 = 0110 1100 1111 0011
from Table 10.2
(c) Converting from binary to hexadecimal i.e. 6CF316 = 110110011110011 2
The binary bits are arranged in groups of four, start-
ing from right to left, and a hexadecimal symbol is Problem 22. Convert the following hexadecimal
assigned to each group. For example, the binary num- numbers into their binary equivalents:
ber 1110011110101001 is initially grouped in fours as: (a) 3F16 (b) A616
1110
   0111
   1010
   1001
   and a hexadecimal symbol
E 7 A 9 (a) Spacing out hexadecimal digits gives:
assigned to each group as above, from Table 10.2. 3 F
      and converting each into binary
Hence 1110011110101001 2 = E7A916 0011 1111
gives as above, from Table 10.2.
Thus, 3F16 = 111111 2
Problem 20. Convert the following binary
numbers into their hexadecimal equivalents: (b) Spacing out hexadecimal digits gives:
A 6
(a) 11010110 2 (b) 1100111 2       and converting each into binary
1010 0110
gives as above, from Table 10.2.
(a) Grouping bits in fours from the right gives: Thus, A616 = 10100110 2
1101
   0110
   and assigning hexadecimal symbols
D 6
Binary, octal and hexadecimal numbers 99

Problem 23. Convert the following hexadecimal

Section A
3. 10001011 2
numbers into their binary equivalents:
(a) 7B16 (b) 17D16 4. 10100101 2
In Problems 5 to 8, convert the given hexadecimal
(a) Spacing out hexadecimal digits gives: numbers into their binary equivalents.
7 B
      and converting each into binary 5. 3716
0111 1011
gives as above, from Table 10.2. 6. ED16
Thus, 7B16 = 1111011 2 7. 9F16

(b) Spacing out hexadecimal digits gives: 8. A2116


1 7 D
         and converting each into
0001 0111 1101
binary gives as above, from Table 10.2.

Thus, 17D16 = 101111101 2

Now try the following Practice Exercise

Practice Exercise 44 Hexadecimal


numbers (Answers on page 860)
In Problems 1 to 4, convert the given binary
numbers into their hexadecimal equivalents.

1. 11010111 2

2. 11101010 2

For fully worked solutions to each of the problems in Practice Exercises 39 to 44 in this chapter,
go to the website:
www.routledge.com/cw/bird

You might also like