0% found this document useful (0 votes)
88 views7 pages

Chapter 2

Computers use the binary number system to represent all data as strings of 0s and 1s. The binary system represents numbers using only two symbols, 0 and 1, whereas the decimal system humans use daily represents numbers using 10 symbols, 0-9. The document explains various number systems including binary, decimal, octal, and hexadecimal. It provides methods for converting numbers between these systems, such as using the remainder method to convert a decimal number to its binary equivalent.

Uploaded by

Placements-help
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)
88 views7 pages

Chapter 2

Computers use the binary number system to represent all data as strings of 0s and 1s. The binary system represents numbers using only two symbols, 0 and 1, whereas the decimal system humans use daily represents numbers using 10 symbols, 0-9. The document explains various number systems including binary, decimal, octal, and hexadecimal. It provides methods for converting numbers between these systems, such as using the remainder method to convert a decimal number to its binary equivalent.

Uploaded by

Placements-help
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/ 7

40

2
Computer Fundamentals & Programming in C

Chapter

BINARY NUMBER SYSTEM


Data is stored in a computer in the form of 0’s and 1’s. This is because computers understand
only binary language (which consists of just two digits, 0 and 1). Therefore, for a computer, all data
and information is reduced to numbers, whether the user stores songs, pictures, numbers, or
documents, all information is treated as binary numbers.
In this chapter, we will learn about the different types of codes that convert human language,
consisting of numeric and alphanumeric characters, into machine language which the computer
understands.

2.1 NUMBER SYSTEM


A number system defines a set of values to represent quantity. We talk about the number of
people attending a class, the number of modules taken by each student and use numbers to represent
grade.
Number System can be categorized in two systems:
(a) Non-Positional Number System (b) Positional Number System.

Non-Positional Number System


In ancient times, people used to count on fingers,
when the fingers became insufficient for counting, stones,
pebbles or sticks were used to indicate values. But it was
very difficult to perform arithmetic with such a number
system as there is no symbol for zero.

Positional Number System People use the base-10 system


because we have 10 fingers!
In this system the value of each digit is defined not
by the symbol but also by the symbol position. Positional
Number System is used to perform arithmetic. Existing 1 3 5 7 8 9 6
Positional number system is decimal number system. 6 5 4 3 2 1 0
Apart from the decimal number system, there are binary 10 10 10 10 10 10 10
number systems, octal number system and hexadecimal
number system.
Base (Radix)
In the number system the base or radix tells the number of symbols used in the system. In the
earlier days, different civilizations were using different radixes. The Egyptian used the radix 2, the
Babylonians used the radix 60 and Mayans used 18 and 20. The base of a number system is indicated
by a subscript (decimal number) and this will be followed by the value of the number. For example
(952) 10, (456) 8, (314) 16.
40
Binary Number System 41

Number System that is used by the computers is:


q Binary [ 2 ]: Uses 2 symbols: the digits 0 and 1.
Some numbers in this system: 0, 000, 1010.
q Decimal [ 10 ]: Uses 10 symbols: the digits 0, 1, 2, … ,9.
Some numbers in this system: 1, 35, 543.
q Octal [ 8 ]: Uses 8 symbols: the digits 0, 1, 2, 3, 4, 5, 6, 7.
q Hexadecimal [ 16 ]: Uses 16 symbols: 0, 1, 2, …., 9, A, B, C, D, E, F.
Notes: When written down, a number may be ambiguous regarding which system it belongs
to. So we will associate a subscript to clear such ambiguities. 1010 in the binary system will be
denoted as 1010[2] to distinguish it from 1010 of the decimal system, which would be denoted as
1010[10]. Similarly, 1010 of the octal system, would be denoted as 1010[8], and 1010 of the Hex
system would be denoted as 1010[16].

Decimal Number System


The decimal system is the system which we use in everyday counting. The number system
includes the ten digits from 0 through 9. These digits are recognized as the symbols of the decimal
system. Each digit in a base ten number represents units ten times the units of the digit to its right.
For example:
9542= 9000 + 500 + 40 +2= (9 × 103) + (5 × 102) + (4 × 101) + (2× 100)

Binary Number System


Computers do not use the decimal system for counting
and arithmetic. Their CPU and memory are made up of =1 =0
millions of tiny switches that can be either in ON and OFF
states. 0 represents OFF and 1 represents ON. In this way
we use binary system. A simple electronic switch can
represent both computer numbers.
The numbers in binary system are represented as combinations of these two symbols.
The decimal system uses power of 10 and binary system uses powers of 2. The binary digit is also
referred to as Bit (the acronym for Binary Digit). A string of 4-bits is called a nibble and a string of 8-
bits is called a byte. A byte is the basic unit of data in computers. The number 125 actually means 1*
102 + 2* 101 +5*100. In binary system, the same number (125) is represented as 1111101 meaning
1*26 +1* 25 +1* 24 +1*23 +1* 22 +0* 21 +1*20.
Computers perform operations on binary number groups called words. Today, most computers
use 32-, 64-, or 128-bit words.

Octal Number System


The octal system is commonly used with computers. The octal number system with its 8 digit
0,1,2,3,4,5,6, and 7 has base 8. The octal system uses a power of 8 to determine the digit of a
number’s position.

Hexadecimal Number System


Hexadecimal is another number system that works exactly like the decimal, binary and octal
number systems, except that the base is 16. Each hexadecimal represents a power of 16. The
system uses 0 to 9 numbers and A to F characters to represent 10 to 15 respectively.
Conversions. Any number in one number system can be converted into any other number
system. There are the various methods that are used in converting numbers from one base to another.
42 Computer Fundamentals & Programming in C

2.2 CONVERSIONS
Conversions of Decimal to Binary
The method that is used for converting of decimals into binary is known as the remainder
method. We use the following steps in getting the binary number :
(a) Divide the decimal number by 2.
(b) Write the remainder (which is either 0 or 1) at the right most position.
(c) Repeat the process of dividing by 2 until the quotient is 0 and keep writing the remainder
after each step of division.
(d) Write the remainders in reverse order.

EXAMPLE—Convert (45)10 into binary number system.

2 45 Remainder
2 22 1
2 11 0
2 5 1
2 2 1
2 1 0
0 1

Thus, (45)10 = (101101)2

Note : In every number system—


(a) The first bit from the right is referred as LSB (Least Significant Bit)
(b) The first bit from the left is referred as MSB (Most Significant Bit).

Conversions of Decimal Fractions to Binary Fractions


For converting decimal fractions into binary fractions, we use multiplication. Instead of looking
for a remainder we look for an integer. The following steps are used in getting the binary fractions :
(a) Multiply the decimal fraction by 2.
(b) If a non-zero integer is generated, record the non-zero integer otherwise record 0.
(c) Remove the non-zero integer and repeat the above steps till the fraction value becomes 0.
(d) Write down the number according to the occurrence.

EXAMPLE—Find the binary equivalent of (0.75) 10 .

Number (to be recorded)


0.75 × 2 = 1.50 1
0.50 × 2 = 1.00 1

Thus, (0.75)10 = (0.11)2.


Moreover, we can write (45.75)10 = (101101.11)2.
Remark : If the conversion is not ended and still continuing; we write the approximation in 16 bits.
Binary Number System 43

EXAMPLE—Find the binary equivalent of (0.9)10 .


Number (to be recorded)
0.9 × 2 = 1.8 1
0.8 × 2 = 1.6 1
0.6 × 2 = 1.2 1
0.2 × 2 = 0.4 0
0.4 × 2 = 0.8 0
0.8 × 2 = 1.6 1
0.6 × 2 = 1.2 1
0.2 × 2 = 0.4 0
0.4 × 2 = 0.8 0
0.8 × 2 = 1.6 1
0.6 × 2 = 1.2 1
0.2 × 2 = 0.4 0
0.4 × 2 = 0.8 0
0.8 × 2 = 1.6 1
0.6 × 2 = 1.2 1
0.2 × 2 = 0.4 0
0.4 × 2 = 0.8 0
0.8 × 2 = 1.6 1
Thus, (0.9)10 = (0.111001100110011001)2 .

Conversion of Decimal to Octal


In converting decimal to octal, we follow the same process of converting decimal to binary.
Instead of dividing the number by 2, we divide the number by 8.
EXAMPLE—Convert (45)10 into octal number system.

8 45 Remainder
8 5 5
8 0 5

Thus, (45) = (55) .


10 8

Conversions of Decimal Fractions to Octal Fractions


We follow the same steps of conversions of decimal fractions to binary fractions. Here, we
multiply the fraction by 8 instead of 2.
EXAMPLE—Find the octal equivalent of (0.75)10.

Number (to be recorded)


0.75 × 8 = 6.00 6

Thus, (0.75)10 = (0.6)8.


And (45.75)10 = (55.6)8.
44 Computer Fundamentals & Programming in C

Conversion of Decimal to Hexadecimal


We divide by 16 instead of 2 or 8. If the remainder is in between 10 to 16, then the number
is represented by A to F respectively.
EXAMPLE—Convert (45)10 into hexadecimal.
16 45 Remainder
16 2 D
16 0 2

Thus (45)10 = (2D)16.


Conversions of Decimal Fractions to Hexadecimal Fractions
Here, we multiply the fraction by 16 instead of 2 or 8. If the non-zero integer is in between 10
to 16, then the number is represented by A to F respectively.
EXAMPLE—Find the hexadecimal equivalent of (0.75)10.

Number (to be recorded)


0.75 × 16 = 12.00 C (12 = C)

Thus, (0.75)10 = (0.C)16.


And (45.75)10 = (2D.C)16.

Conversions of Binary to Decimal


In converting binary to decimal, we use the following steps :
(a) Write the weight of each bit.
(b) Get the weighted value by multiplying the weighted position with the respective bit.
(c) Add all the weighted value to get the decimal number.
EXAMPLE—Convert (101101)2 into decimal number system.

Binary Number 1 0 1 1 0 1

Wt. of each bit 25 24 23 22 21 20

Weighted Value 1 × 25 0 × 24 1 × 23 1 × 22 0×2 1 × 20

Solved Multiplication 32 0 8 4 0 1

Thus, (101101) 2 = 1 × 25+ 0 × 24 + 1 × 23 + 1 × 22 + 0 × 21 + 1 × 20.


= 32 + 0 + 8 + 4 + 0 + 1
= 45

Conversions of Binary Fractions to Decimal Fractions


The conversions of binary fractions to the decimal fractions is similar to conversion of binary
numbers to decimal numbers. Here, instead of a decimal point we have a binary point. The exponential
expressions (or weight of the bits) of each fractional placeholder is 2-1, 2-2………
Binary Number System 45

EXAMPLE—Convert (101101.11)2 into decimal number system.

Binary Number 1 0 1 1 0 1 1 1

Wt. of each bit 25 24 23 22 21 20 2–1 2–2

Weighted Value 1 × 25 0 × 24 1 × 23 1 × 22 0×2 1 × 20 1 × 2–1 1 × 2–2

Solved Multiplication 32 0 8 4 0 1 0.5 0.25

Thus, (101101.11)2 = 32 + 0 + 8 + 4 + 0 + 1 + 0.5 + 0.25 = 45.75


Conversions of Binary to Octal
We use the following steps in converting binary to octal:
(a) Break the number into 3-bit sections starting from LSB to MSB.
(b) If we do not have sufficient bits in grouping of 3-bits, we add zeros to the left of MSB so
that all the groups have proper 3-bit number.
(c) Write the 3-bit binary number to its octal equivalent.
EXAMPLE—Convert (101101) 2 into octal.

Binary Number 101 101

Octal Number 5 5

Thus, (101101)2 = (55)8 .

EXAMPLE—Convert (1101101)2 into octal.

Binary Number 001 101 101

Octal Number 1 5 5

Thus (1101101)2 = (155)8.

Conversions of Binary Fractions to Octal Fractions


We use the following steps in converting binary fractions to octal fractions:
(a) Break the fraction into 3-bit sections starting from MSB to LSB.
(b) In order to get a complete grouping of 3 bits, we add trailing zeros in LSB.
(c) Write the 3-bit binary number to its octal equivalent.
EXAMPLE—Convert (101101.11)2 into octal.

Binary Number 101 101 110


Octal Number 5 5 6

Thus, (101101)2 = (55.6)8.


Conversions of Binary to Hexadecimal
We convert binary to hexadecimal in the similar manner as we have converted binary to octal.
The only difference is that here, we form the group of 4 –bits.
46 Computer Fundamentals & Programming in C

EXAMPLE—Convert (101101)2 into hexadecimal.

Binary Number 0010 1101


Decimal Number 2 13
Hexadecimal Number 2 D

Thus, (101101)2 = (2D)16.

Conversions of Binary Fractions to Hexadecimal Fractions


We convert binary fractions to hexadecimal fractions in the similar manner as we have converted
binary fractions to octal fractions. The only difference is that here we form the group of 4 –bits.
EXAMPLE—Convert (101101.11) 2 into hexadecimal.

Binary Number 0010 1101 1100


Decimal Number 2 13 12
Hexadecimal Number 2 D C

Thus, (101101.11)2 = (2D.C)16.

Conversions of Octal to Decimal


We follow the same steps of conversion of binary to decimal. The only difference is that here
weight of nth bit is 8n-1 instead of 2n-1.
EXAMPLE—Convert (55)8 into decimal number system.

Octal Number 5 5
Wt. of each bit 81 80
Weighted Value 5×8 5 × 80
Solved Multiplication 40 5

Thus, (55)8 = 40 + 5 = 45

Conversions of Octal Fractions to Decimal Fractions


The weight of the bit of the fraction placeholder is 8-1, 8-2………. We follow the same steps of
conversion of binary fractions to decimal fractions.
EXAMPLE—Convert (55.6)8 into decimal number system.

Octal Number 5 5 6
Wt. of each bit 81 80 8–1
Weighted Value 5×8 5 × 80 6 × 8–1

Solved Multiplication 40 5 0.75

Thus, (55.6)8 = 40 + 5 + 0.75 = 45.75

You might also like