Number System: Amity School of Engineering and Technology
Number System: Amity School of Engineering and Technology
Number System
Number System
• Decimal Number System
• Binary Number System
• Octal Number System
• HexaDecimal Number System
2
Decimal Number System
3
Decimal Number System
• Each position represents a specific power
of the base (10).
• For example, the decimal number 1234
consists of the digit 4 in the unit's position,
3 in the tens position, 2 in the hundreds
position, and 1 in the thousands position,
and its value can be written as
=((4 × 1) + (3 × 10) + (2 × 100) + (1 × 1000))
=1234
4
Binary Number System
• Uses two digits, 0 and 1.
• Also called base 2 number system
• Each position in a binary number
represents a 0 power of the base (2).
• Example: 20
• Last position in a binary number
represents an x power of the base (2).
• Example: 2x where x represents the last
position - 1.
5
Octal Number System
• Uses eight digits, 0,1,2,3,4,5,6,7.
• Also called base 8 number system
• Each position in an octal number
represents a 0 power of the base (8).
Example: 80
• Last position in an octal number
represents an x power of the base (8).
• Example: 8x where x represents the last
position - 1.
6
Hexadecimal Number System
• Uses 10 digits and 6 letters,
0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F.
• Letters represents numbers starting from 10. A =
10, B = 11, C = 12, D = 13, E = 14, F = 15.
• Also called base 16 number system.
• Each position in a hexadecimal number
represents a 0 power of the base (16). Example
160.
• Last position in a hexadecimal number
represents an x power of the base (16). Example
16x where x represents the last position - 1.
7
Values of Each Digit
• A value of each digit in a number can be determined
using
• The digit
• The position of the digit in the number
• The base of the number system (where base is defined
as the total number of digits available in the number
system).
S.No. Number System
Number System
Base Digits
1 Decimal number system 10 0-9
2 Binary Number System 2 0-1
9
Number System Conversions
10
Binary ()2 to Decimal ()10
11
Binary ()2 to Decimal ()10
• (10101)2 to ()10
Step 1: Multiply each digit by base from LSB and take power starting
from 0
13
Binary ()2 to Decimal ()10
• (1101.0111)2 to ()10
1101.0111 = (1×23) + (1×22) + (0×21) + (1×20)
+ (0×2-1) + (1×2-2) + (1×2-3) + (1×2-4)
= 8 + 4 + 0 + 1 + 0 + 1/4 + 1/8 + 1/16
= 8 + 4 + 0 + 1 + 0 + 0.25 + 0.125 + 0.062
5 = 13.437510
14
Binary ()2 to Decimal ()10
• (1011.111)2 to ()10
1011.111 = (1×23) + (1×21) + (1×20) (1×2-
1
) + (1×2-2) + (1×2-3)
= 8 + 2 + 1 + 0.5 + 0.25 + 0.125 = 11.87510
• 11.001 = (1×21) + (1×20) + (1×2-
3
) = 2 + 1 + 0.125 = 3.12510
15
Octal ()8 to Decimal ()10
• Base of an Octal
Numbers system
is 8 (base-8)
• octal number system
uses only eight digits
(0 through 7)
16
Octal ()8 to Decimal ()10
• (232)8 to ()10
=( 2×82 ) + ( 3×81 ) + ( 2×80)
=2x64 + 3x8 + 2x1
=128+24+2 =154
• (1576)8 to ()10
=1x8 3
+ 5x8 2
+ 7x8 1
+ 6x80
=
1x512 + 5x64 + 7x8 + 6x1
=512 + 320 + 56 + 6 = 894
17
Octal ()8 to Decimal ()10
18
Octal ()8 to Decimal ()10
• (7.12172)8 to (?)10
= (7×80)+ (1×8-1) + (2×8-2) + (1×8-3)+ (7×8-
4
) + (2×8-5)
=7+0.125+0.03125+0.001953125+0.001708
984375+0.00006103515624
=10.1599..
=10.16(approx.)
19
Octal ()8 to Decimal ()10
• (152.54)8 to (?)10
= (1 × 8²) + (5 × 8¹) + (2 × 8⁰) + (5 × 8⁻¹) +
(4 × 8⁻²)
=1 ×64 +5 ×8+2 ×1+5 ×0.125+4 ×0.015625
=106.6875
20
Hexa Decimal ()16 to
Decimal ()10
• (AB34)₁₆ = (?)₁₀
= (10 × 16³) + (11 × 16²) + (3 × 16¹) + (4 ×
16⁰)
=(10 × 4096) + (11 × 256) + (3 × 16) + (4 ×
1)
=40960+2816+48+4
= (43828)₁₀
21
Hexa Decimal ()16 to
Decimal ()10
• (AB34)₁₆ = (?)₁₀
= (10 × 16³) + (11 × 16²) + (3 × 16¹) + (4 ×
16⁰)
=(10 × 4096) + (11 × 256) + (3 × 16) + (4 ×
1)
=40960+2816+48+4
= (43828)₁₀
22
Hexa Decimal ()16 to
Decimal ()10
( EF.B1)16= ( ? )10
=E x 161 + F x 160 + B x 16-1 + 1 x 16-2
= 14 x 16 + 15 x 1 + 11 x ( 1 / 16 ) + 1 x
( 1 / 256 )
= 224 + 15 . ( 0. 6 8 7 5 ) + ( 0 . 0 0 3 9 0 6
2 5 )
= 239 + 0. 6914
= 239 . 691406
23
Test Your Understanding
• (10111.1101)2 to ()10
• (247.35)8 to ()10
• (A214.9E)16 to ()10
24
Number System Conversions
25
Decimal ()10 to Binary ()2
26
Decimal ()10 to Binary ()2
• Convert =
• =(
27
Decimal ()10 to Binary ()2
• =
Step-1 Begin with the decimal fraction and
multiply by 2. The whole number part of the
result is the first binary digit to the right of
the point.
.625 x 2 = 1.25, the first binary digit to the
right of the point is a 1. So far, we have .625
= .1??? .
28
Decimal ()10 to Binary ()2
29
Decimal ()10 to Binary ()2
•Step
-3 Discard the whole number part of
the previous result (.50 in this case) and
multiply by 2 once again
.50 x 2 = 1.00
So,.625 = .101?
We are finished in Step 3, because we had
0 as the fractional part of our result there.
So, =
30
Decimal ()10 to Binary ()2
•Infinite
Binary Fractions
Covert =
Step1. .1 x 2 = 0.2
Step 2. .2 x 2 = 0.4
Step 3. .4 x 2 = 0.8
Step 4. .8 x 2 = 1.6
Step 5. .6 x 2 = 1.2
31
Decimal ()10 to Binary ()2
•Infinite
Binary Fractions
So, =
33
Decimal ()10 to Octal ()8
•=
Step 1 Divide 567 by 8
Step 2 Continue dividing the quotient by 8
until you get a quotient of zero
Step 3 Finally write the remainders in the
reverse order to get octal equivalent of
decimal number 567
34
Decimal ()10 to Octal ()8
•So,=
35
Decimal ()10 to Octal ()8
36
Decimal ()10 to Octal ()8
• =
×8=1.3125
0.3125×8=2.5
0.5×8=4.0
So, =
37
Decimal ()10 to Octal ()8
• =
=
0.16×8=1.28
0.28×8=2.24
0.24×8=1.92
0.92×8=7.36
0.36×8=2.88
So, =
38
Decimal ()10 to Hexa
Decimal ()16
• First, divide the decimal number by 16,
• Keep aside the remainder left.
• Again divide the quotient by 16 and repeat
till you get the quotient value equal to
zero.
• Now take the values of the remainder’s in
the reverse order to get the hexadecimal
numbers.
39
Decimal ()10 to Hexa
Decimal ()16
•=
40
Decimal ()10 to Hexa
Decimal ()16
• To convert a decimal fraction to
hexadecimal, multiply by 16;
• The integer part of the result is the first
digit of the hexadecimal fraction.
• Repeat the process with the fractional part
of the result, until it is null or within
acceptable error bounds.
41
Decimal ()10 to Hexa
Decimal ()16
•=
1. 0.06640625 x 16=1.0625
2. 0.0625 x 16 =1.0
3. 0 x 16=0.0
42
Test Your Understanding
• (296.5)10 to ()2
• (813.24)10 to ()8
• (479.36)10 to ()16
43
Octal ()8 to Binary ()2
44
Binary ()2 to Octal ()8
• Starting from the LSB, make groups of
three bits.
• If there are one or two bits less in making
the groups, 0s can be added after the
MSB
• Convert each group into its equivalent
octal number
45
Binary ()2 to Octal ()8
46
Octal ()8 to Binary ()2
• (145)8=(?)2
=(001 100 101)8
=(1100101)8
• (352.563)8=(?)2
=(011 101 010.101 110 011)2
=(011101010.101110011)2
47
Test your Understanding
• (234.56)8=(?)2
• (124.05)8=(?)2
48
Hexadecimal Binary
Number Number
0 0000
1 0001
2 0010
3 0011
4 0100
5 0101
6 0110
7 0111
8 1000
9 1001
A 1010
B 1011
C 1100
D 1101
E 1110
F 1111
49
Binary to Hexadecimal
• Starting from the LSB make groups of four
bits.
• If there are one or two bits less in making
the groups, 0s can be added after MSB.
• Convert each group into its equivalent
octal number.
50
Binary to Hexadecimal
51
Hexa decimal()16 to Binary ()2
• (2C1)16 = (001011000001)2
• (9DB2)16 = (1001110110110010)2
52
Test your Understanding
• (234.56)16=(?)2
• (124.05)16=(?)2
53
Binary Number
Representation
• Unsigned Representation
• Signed Representation
54
Unsigned Representation
• Non negative numbers can be represented
• No>=0
• Negative numbers cannot be represented
• Example- age, no of children in class
55
Signed representation
56
Ways to Represent
Signed Numbers
• Sign and magnitude (SNM)
• 1’s complement
• 2’s complement
57
Example
Decimal Unsigned Sign and 1’s 2’s
Number Magnitude complement complement(
1’s
complement
+1)
+10 1010 0 1010 0 1010 0 1010
-10 … 1 1010 1 0101 1 0110
(shown in
table)
- 25 (6-bit 1 11001 1 00110 1 00111
required)
+ 25 11001 0 11001 0 11001 0 11001
58
Example
Binary Unsigned Sign and 1’s 2’s
Number Magnitude complement complement(
1’s
complement
+1)
000 0 +0 0 0
001 1 +1 1 1
010 2 +2 2 2
011 3 +3 3 3
100 4 - 0 - 3 (011) -4
(011+1=100)
101 5 - 1 - 2 (0 10) -3
(010+1=011)
110 6 - 2 -1 (001) -2
(001+1=010)
111 7 - 3 - 0 (000) -1
(000+1=001)
59
Range of Example
From To
Unsigned (total 8 0 7
representation)
Sign and Magnitude -3 +3
(total 7 distinct value, 0
repeated)
1’s complement (total 7 -3 +3
distinct value, 0
repeated)
60
8-bit Number
• =256
Unsigned-0 to 255
Signed and Magnitude- -127 to +127
1’s complement- -127 to +127
2’s complement- -128 to +127
• =1024
Unsigned-0 to 1023
Signed and Magnitude- -511 to +511
1’s complement- -511 to +511
2’s complement- -512 to 511
61
More Examples
Decimal Unsigned Sign and 1’s 2’s
Number Magnitude complement complement(
1’s
complement
+1)
+ 50 110010 0 110010 0 110010 0 110010
- 50 Cannot be 1 110010 1 001101 1 001110
represented
8 1000 0 1000 0 1000 0 1000
-8 1 1000 1 0111 1 1100
+31 11111 0 11111 0 11111 0 11111
-31 1 11111 1 00000 1 00001
62
Binary Arithmetic
• The arithmetic of binary numbers means
the operation of binary
addition, binary subtraction, binary multi
plication and binary division.
63
Binary Addition
• There are four steps in binary addition
they are written below
• 0+0=0
• 0+1=1
• 1+0=1
• 1 + 1 = 0 (carry 1 to the next significant bit)
64
Example
• 100101 + 10101 = ?.
65
Example
• 10111 + 110001=?
• 1011001 + 111010=?
66
Binary Subtraction
• Rules
0-0=0
1-0=1
1-1=0
0 - 1 = 1 with a borrow of 1
67
Example
• 1110110-1010111
68
Example
• 100010110 − 1111010 = 10011100:
69
Example
• Subtract 11010.101 from 101100.011
1 0 1 1 0 0 . 0 1 1
1 1 0 1 0 . 1 0 1
1 0 0 0 1 . 1 1 0
70
Binary Multiplication
• The rules of binary multiplication are:
0×0=0
0×1=0
1×0=0
1 × 1 = 1 [No borrow or carry method is
applicable here]
71
Example
• 9×5 (1001 × 101)
1 0 0 1
× 1 0 1
1 0 0 1
0 0 0 0
1 0 0 1
1 0 1 1 0 1
72
Binary Division
• The main rules of the binary division
include:
• 1÷1 = 1
• 1÷0 = 0
• 0÷1 = Meaningless
• 0÷0 = Meaningless
73
Example
74
Subtraction by 1’s
Complement
Case 1:Addition of the positive number with
a negative number when the positive
number has a greater magnitude
• find the 1's complement of the of the
subtrahend. Change 0 to 1 and vice versa
• add the complement number with the
minuend
• If got a carry, add the carry to its LSB. Else
take 1's complement of the result which
will be negative 75
Example
10101 – 00111
• Take 1's complement of subtrahend 00111,
which comes out 11000. Now, sum them.
So,
• 10101+11000 =1 01101.
we get the carry bit 1, so add this to the LSB
of a given result
01101+1=01110(Answer)
76
Subtraction by 1’s
Complement
• Case 2: Addition of positive and
negative number when negative
number has greater magnitude.
When the negative number has greater
magnitude, then take 1’s complement of
negative number and add with given positive
number. Since there will not be any end-
around carry bit, so take 1’s complement of
the result and this result will be negative.
77
Example
10101 – 10111
• Take 1's complement of subtrahend 10111,
which comes out 01000. Now, add both of
the numbers. So,
10101+01000 =11101.(No carry)
So, calculate 1’s complement of result
Answer=00010
And the answer is negative in this case
78
Subtraction by 1’s
Complement
• Case 3: Addition of two negative numbers
You need to take 1’s complement for both
numbers, then add these 1’s complement of
numbers. Since there will always be end-
around carry bit, so add this again to the
LSB of result. Now, take 1’s complement
also of previous result, so this will be
negative number.
79
Example
• add -10 and -5 in five bit register
0 1 0 1 0
0 0 1 0 1
81
2’ Complement
• 2’ complement of -50 is 1 001110
=32 =16 =8 =4 =2 =1
Bit (
1 0 0 1 1 1 0
1 0 0 1 1 1 0
1 1
0 1 1 1 =7
0 1 1 0 =6
1 1 0 1 =13
83
Overflow/underflow
Consider an example to add 15 and 10 in
unsigned representation
1 1
1 1 1 1 =15
1 0 1 0 =10
1 0 0 1 =9/25
1
84
Overflow/underflow
• Consider a 4-bit signed number.
7(0111)+6(0110). In signed number 0 is
MSB and is used to present sign. In this
no is represented in 2’s complement
(range is from -8 to +7)
1 1
0 1 1 1 =7(2’s complement of 7)
0 1 1 0 =6 (2’s complement)
1 1 0 1 = -8+5=-3(2’s complement)
85
Overflow/underflow
Consider an example to add 15 and 10 in
binary representation for signed
representation
1 1
1 1 1 1 =-1(2’s complement)
1 0 1 0 =-6 (2’s complement)
1 0 0 1 =-7 (-8+1=-7)
86
Overflow/underflow
Consider another example for signed
representation
1 0 0 0 =-8(2’s complement)
1 0 0 1 =-7 (2’s complement)
0 0 0 1 =1 (2’s complement)
87
Example
• Adding one positive and one negative
number will never cause overflow or
underflow In the example shown below
10+(-16) in 2’s complement is represented
10= 0 1 0 1 0
-16= 1 1 0 1 0
1 1 0 1 0
-6=
88
Memory Storage unit
89
Bit
• The smallest unit of data in a computer is
called Bit (Binary Digit). A bit has a single
binary value, either 0 or 1.
• stored as either above or below a
designated level of electrical charge in a
single capacitor within a memory device.
90
Nibble
• Half a byte is nibble
91
Byte
• In most computer systems, a byte is a unit
of data that is eight binary digits long. A
byte is the unit most computers use to
represent a character such as a lette,
number or typographic symbol .
• In some computer systems, four bytes
constitute a word, a unit that a computer
processor can be designed to handle
efficiently as it reads and processes each
instruction 92
Octet
• In some systems, the term octet is used
for an eight-bit unit instead of byte. In
many systems, four eight-bit bytes or
octets form a 32-bit word.
93
Kilobyte
94
Megabyte
• measure
of computer processor storage
and real and virtual memory
=1,048,576 bytes
• Abbreviated as MB.
95
Gigabyte
• A Gigabyte
is a measure of computer
data storage capacity and is “roughly” a
billion bytes.
=1,073,741,824 bytes
96
Terabyte
• A Terabyte is
a measure of computer
storage capacity
97
Petabyte
• A Petabyte (PB)
is a measure of memory
or storage capacity
bytes
98
Exabyte
• An Exabyte (EB)
is a large unit of
computer data storage
bytes
99
Zettabyte
100
Yottabyte
• A Yottabyte is equal to one septillion
bytes
• It has 1024 Zettabyte of storage
101
References
ANSI 89 – American National Standards Institute, American
National Standard for Information Systems Programming
Language C, 1989.
Kernighan 78 – B. W. Kernighan and D. M. Ritchie, The C
Programming Language, Prentice-Hall: Englewood Cliffs, NJ,
1978. Second edition, 1988.
Thinking 90 – C* Programming Guide, Thinking Machines
Corp. Cambridge Mass., 1990.
Programming in ANSI C, E. Balagurusamy. McGrawHill
Let Us C, Yashvant Kanetkar, BPB Publications
Programming in C, Reema Thareja, Oxford University Press
102
Thank You