The document discusses various number systems including decimal, binary, octal, and hexadecimal, highlighting their bases, symbols, and conversions. It explains how to represent signed numbers using different methods such as signed magnitude, 1's complement, and 2's complement, along with techniques for converting between bases. Additionally, it covers concepts of positional versus non-positional number systems, and includes examples of arithmetic and conversions.
Overview of Chapter 2 on Number Systems including Binary, Octal, Hexadecimal, and their conversions.
Definition of number systems, their representation, and examples showing equivalent decimal values.
Categorization of number systems: Decimal, Binary, Octal, and Hexadecimal with their bases and symbols.
Numerical representations of different number systems and methods for converting between bases.
Step-by-step examples on converting decimal to binary, octal, and hexadecimal, and vice versa.
Techniques for converting between octal and binary, hexadecimal and binary, and their examples.
Differentiates between positional (weighted) and non-positional (non-weighted) number systems.
Concept of signed binary numbers, representation forms including sign magnitude, 1's complement, and examples.
Explanation and examples of finding the 2's complement of signed integers.
Assignments and examples on performing subtraction, addition using 9’s and 10’s complement. Discussion on signed binary numbers with focus on addition and subtraction in binary formats. Methodology for converting decimal numbers into binary floating-point format as per IEEE standards.
Chapter 2: NumberSystem
2.1 Binary, Octal & Hexadecimal Number Systems and their conversions
2.1.1 Representation of Signed Numbers, Floating Point Number
2.1.2 Binary Arithmetic
2.2 Representation of BCD, ASCII, Excess 3, Gray Code, Error Detection
and Correcting Codes.
1
A numbersystem defines how a number can
be represented using distinct symbols.
A number can be represented differently in
different systems.
For example, the two numbers (2A)16 and (52)8
both refer to the same quantity, (42)10, but their
representations are different.
3
4.
Number system canbe categorized as
1. Decimal number system
2. Binary number system
3. Octal number system
4. Hexadecimal Number System
4
5.
o Each numbersystem is associated with a base or radix
o The decimal number system is said to be of base or
radix10
o A number in base r contains r digits 0,1,2,...,r-1
o Decimal (Base 10): 0,1,2,3,4,5,6,7,8,9
5
6.
The worddecimal is derived from the Latin root
decem(ten). In this system the base b = 10 and
we use ten symbols.
S = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}.
6
7.
The wordbinary is derived from the Latin root
bini (or two by two).
In this system the base b = 2 and we use
only two symbols,
S = {0, 1}
The symbols in this system are often referred
to as binary digits or bits.
7
8.
The wordhexadecimal is derived from the Greek root
hex (six) and the Latin root decem (ten).
In this system the base b = 16 and we use sixteen
symbols to represent a number.
The set of symbols is
S = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E,F}
The symbols A, B, C, D, E, F are equivalent to
10, 11, 12, 13, 14, and 15 respectively.
The symbols in this system are often referred to as
hexadecimal digits.
8
9.
The word octalis derived from the Latin root
octo (eight).
In this system the base b = 8 and we use
eight symbols to represent a number.
The set of symbols is:
S = {0, 1, 2, 3, 4, 5, 6, 7}
9
10.
Common Number Systems
10
SystemBase Symbols Used by
Humans?
Used in
Computers?
Decimal 10 0, 1, … 9 Yes No
Binary 2 0, 1 No Yes
Octal 8 0, 1, … 7 No No
Hexa-
decimal
16 0, 1, … 9,
A, B, … F
No No
Conversion among Bases
•Possibilities
• Example
12
Hexadecimal
Decimal Octal
Binary
2510 = 110012 = 318 = 1916 Base
13.
Decimal to Binary
•Technique
– Divide by two, keep track of the remainder
– First remainder is bit 0 (LSB, least-significant bit)
– Second remainder is bit 1 and so on
13
Decimal Binary
Example (Decimal toBinary)
15
0.687510 = ?2
0.6875 x 2 = 1.3750 1 0.3750
+
0.3750 x 2 = 0.7500 0 0.7500
+
0.7500 x 2 = 1.5000 1 0.5000
+
0.5000 x 2 = 1.0000 1 0.0000
+
0.687510 = 0.10112
integer fraction
16.
Binary to Decimal
•Technique
– Multiply each bit by 2n, where n is the “weight” of the
bit
– The weight is the position of the bit, starting from 0
on the right
– Add the results
16
Binary Decimal
17.
Example (Binary toDecimal)
17
1 0 1 0 1 1
1 x 20
1 x 21
0 x 22
1 x 23
0 x 24
1 x 25 +
+
+
+
+
1
2
0
1010112 =
0
32 +
+
+
+
+
4310
4310
8
18.
Example (Binary toDecimal)
18
1 1 . 1 1
1 x 20
1 x 21 +
1
2
11.112 =
+
3.7510
3.7510
1 x 2-2
1 x 2-1 +
0.25
0.5 +
+
+
19.
Decimal to Octal
•Technique
– Divide by eight
– Keep track of the remainder
19
Decimal Octal
Example (Decimal toOctal)
21
0.687510 = ?8
0.6875 x 8 = 5.5000 5 0.5000
+
0.5000 x 8 = 4.0000 4 0.0000
+
0.687510 = 0.548
integer fraction
22.
Octal to Decimal
•Technique
– Multiply each bit by 8n, where n is the “weight” of the
bit
– The weight is the position of the bit, starting from 0
on the right
– Add the results
22
Octal Decimal
23.
Example (Octal toDecimal)
23
7 2 4
4 x 80
2 x 81
7 x 82 +
+
7248 =
46810
46810
4
16
448 +
+
24.
Example (Octal toDecimal)
24
4 3 . 2 5
3 x 80
4 x 81 +
3
32
43.258 =
+
35.328110
35.328110
5 x 8-2
2 x 8-1 +
0.0781
0.25 +
+
+
25.
Decimal to Hexa-Decimal
•Technique
– Divide by 16
– Keep track of the remainder
25
Decimal Hexa-Decimal
Hexa-Decimal to Decimal
•Technique
– Multiply each bit by 16n, where n is the “weight” of
the bit
– The weight is the position of the bit, starting from 0
on the right
– Add the results
27
Hexa-Decimal Decimal
28.
Example (HexaDecimal toDecimal)
28
A B C
C x 160
B x 161
A x 162 +
+
ABC16 =
274810
274810
12 x 160
11 x 161
10 x 162
+
+
12
176
2560 +
+
29.
Octal to Binary
•Technique
– Convert each octal digit to a 3-bit equivalent binary
representation
29
Octal Binary
Hexa-Decimal to Octal
•Technique
– Convert Hexa-Decimal to Binary
– Regroup bits in three from right
– Convert Binary to Octal
41
Hexa-Decimal Octal
42.
Example (Hexa-Decimal toOctal)
42
1F0C16 = ?8
1 F 0 C
1100
0000
1111
1F0C16 = 174148
0001
100
001
100
4
1
4
111
7
001
1
000
0
43.
Positional Number System
•A positional number system is also known as
weighted number system.
• As the name implies there will be a weight
associated with each digit.
• Few examples of positional number system
are decimal number system, Binary number
system, octal number system ,etc.
43
44.
Non-Positional Number System
•Non-positional number system is also known
as non-weighted number system.
• Digit value is independent of its position. Non-
positional number system is used for shift
position encodes and error detecting purpose.
• Few examples of non-weighted number
system are gray code, roman code, excess-3
code, etc.
44
45.
Signed numbers
• Digitalsystems such as computer must be able to
handle both positive and negative numbers. A signed
binary number consists of both signed and magnitude
information.
• Eg: Signed number : +7
7 = Binary Number 111
+7 = 0 111
• Sign indicates whether a number is positive or negative
and magnitude is the value of the number. Left most
bit is the sign bit.
• ‘0’ sign bit indicates a positive number and ‘1’ sign bit
indicates a negative number.
45
46.
Signed numbers
There are3 forms in which sign integer numbers
can be represented in binary.
1. Signed magnitude
2. 1’s Complement
3. 2’s Complement
46
47.
Signed Magnitude form
•When a signed binary number is represented in a sign
magnitude form, left most bit is the signed bit and
remaining bits are magnitude bit.
• The magnitude bits are in a true binary for both positive
and negative numbers.
• Eg : Represent decimal number +25 on 8-bit signed
binary number.
25 (11001)2
+25 0 0011001
+ Sign Magnitude
48.
Example
Q. Similarly -75is represented (8-bit) as ???
Ans: 1 1001011
75 = 1001011
-75 = 1 1001011
48
49.
1’s Complement
49
1 11 1
1 1 0 1
0 0 1 0
-
(1’s complement of 1101)
1 1 1 .
1 0 1 .
0 1 0 .
-
(1’s complement of 101.01)
1 1
0 1
1 0
1’s complement of a binary number is obtained by subtracting
each digit of that binary number from 1.
Example
50.
1’s Complement Form
•Positive Numbers are simply represented as it is.
• If the number is negative, First represent the number
with positive sign and then take 1’s complement of that
number.
• Ex: Using 8-bit, find 1’s complement of decimal number
-25.
Step-1 : +25 = 00011001
Step-2 : 1’s complement : 11100110
Q. Find 1’s complement of -75 using 8-bit
Step-1 : +75 = 0 1001011
Step-2 : 1’s complement : 10110100
51.
2’s Complement
• 2’scomplement of a binary number is obtained by
adding 1 to its 1’s complement.
51
1 1 1 1
1 1 0 0
0 0 1 1
-
(2’s complement of 1100)
0 1 0 .
-
(2’s complement of 101.01)
1 1 1 . 1 1
1 0 1 . 0 1
1 0
1
0 1 0 0
1
+ +
0 1 0 1 1
.
Example
52.
2’s Complement form
•Positive Numbers are simply represented as it is.
• If the number is negative, First represent the number
with positive sign and then take 2’s complement of that
number.
E.g. : Find 2’s complement of -25 using 8-bit
+25 = 00011001
1’s complement = 11100110
+ 1
11100111
Q. Find 2’s complement of -75
Ans: (10110101)
53.
Representation of negativenumber in 2’s
complement form
• Express -65.5 in 12 bit 2’s complement form.
53
2 65 1
2 32 0
2 16 0
2 8 0
2 4 0
2 2 0
2 1 1
0
0.5 x 2 = 1.0
65.510 = 01000001.10002
So, result in 12-bit binary is as follows:
For negative number, we have to
convert this into 2’s complement form
-65.510 =10111110.10002
54.
Assignment
Questions:
1. Convert (1101010)2to octal, decimal and hexadecimal.
2. Convert (1011.01)2 to octal, decimal and hexadecimal.
3. Convert (35.43)10 to binary, octal and hexadecimal.
4. Convert (635.74)8 to binary, decimal and hexadecimal.
5. Convert (D6A)16 to binary, octal & decimal.
6. Express the decimal number -39 as an 8-bit number in
sign magnitude, 1’s complement and 2’s complement
form.
55.
9’s Complement
• 9’scomplement of a decimal number is obtained by
subtracting each digit of that decimal number from 9.
55
9 9 9 9
3 4 6 5
6 5 3 4
-
(9’s complement of 3465)
9 9 9 .
7 8 2 .
2 1 7 .
-
(9’s complement of 782.54)
9 9
5 4
4 5
Example
56.
10’s Complement
• 10’scomplement of a decimal number is obtained by
adding 1 to its 9’s complement.
56
9 9 9 9
3 4 6 5
6 5 3 4
-
(10’s complement of 3465)
2 1 7 .
-
(10’s complement of 782.54)
9 9 9 . 9 9
7 8 2 . 5 4
4 5
1
6 5 3 5
1
+ +
2 1 7 4 6
.
Example
57.
Subtraction using 9’scomplement
• Obtain 9’s complement of subtrahend
• Add the result to minuend and call it
intermediate result
• If carry is generated then answer is positive
and add the carry to Least Significant Digit
(LSD)
• If there is no carry then answer is negative and
take 9’s complement of intermediate result
and place negative sign to the result.
57
Example
59
7 4 5.
4 3 6 .
- 8 1
6 2
2) 436.62 - 745.81
2 5 4 .
+ 1 8
6 9 0 . 8 0
3 0 9 . 1 9
3 0 9 . 1 9
-
4 3 6 . 6 2
-
9’s complement
9’s complement
As carry is not generated, so take 9’s
complement of the intermediate
result and add ‘ – ‘ sign to the result
60.
Subtraction using 10’scomplement
• Obtain 10’s complement of subtrahend
• Add the result to minuend
• If carry is generated then ignore it and result
itself is answer
• If there is no carry then answer is negative and
take 10’s complement of result and place
negative sign to the result.
60
• Solve thefollowing division
1.(11001) by (101)
Ans:101
2. (111)2 by (11)2
Ans: 10 remainder 1
3. (110000) by (100)
Ans:
76.
Subtraction using 1’sComplement
• Obtain 1’s complement of subtrahend
• Add the result to minuend and call it
intermediate result
• If carry is generated then answer is positive
and add the carry to Least Significant Digit
(LSD)
• If there is no carry then answer is negative and
take 1’s complement of intermediate result
and place negative sign to the result.
76
Example
78
2) 43.25 -89.75
As carry is not generated, so take 1’s
complement of the intermediate
result and add ‘ – ‘ sign to the result
43.
89.
-
25
75
- 46.50
1’s complement
101 . 0 1
011
00 0 0
+ 100 .
110
10 0 01 1
00 1.
0 01
10 1
1 11
11 0.
1 10
01 0
0 00
1’s complement
79.
Subtraction using 2’sComplement
• Obtain 2’s complement of subtrahend
• Add the result to minuend
• If carry is generated then ignore it and result
itself is answer
• If there is no carry then answer is negative and
take 2’s complement of result and place
negative sign to the result.
79
Example
81
2) 43.25 -89.75
As carry is not generated, so take 2’s
complement of the intermediate
result and add ‘ – ‘ sign to the result
43.
89.
-
25
75
- 46.50
2’s complement
101 . 0 1
011
00 0 0
+ 100 .
110
10 0 10 0
00 1.
0 10
10 1
1 00
11 0.
1 10
01 0
0 00
2’s complement
82.
Signed Binary Numbers
•To represent negative integers, we need a notation for negative values.
• It is customary to represent the sign with a bit placed in the leftmost position
of the number since binary digits.
• The convention is to make the sign bit 0 for positive and 1 for negative.
• Different methods of representations (example):
• Table 1.3 lists all possible four-bit signed binary numbers in the three
representations.
Signed Binary Numbers
•Arithmetic addition
– The addition of two numbers in the signed-magnitude system follows the rules of
ordinary arithmetic. If the signs are the same, we add the two magnitudes and give the
sum the common sign. If the signs are different, we subtract the smaller magnitude
from the larger and give the difference the sign if the larger magnitude.
– The addition of two signed binary numbers with negative numbers represented in
signed-2's-complement form is obtained from the addition of the two numbers,
including their sign bits.
– A carry out of the sign-bit position is discarded.
• Example:
85.
Signed Binary Numbers
•Arithmetic Subtraction
– In 2’s-complement form:
• Example:
1. Take the 2’s complement of the subtrahend (including the sign bit)
and add it to the minuend (including sign bit).
2. A carry out of sign-bit position is discarded.
( ) ( ) ( ) ( )
( ) ( ) ( ) ( )
A B A B
A B A B
( 6) ( 13) (11111010 11110011)
(11111010 + 00001101)
00000111 (+ 7)
BINARY REPRESENTATION OFFLOATING POINT
NUMBERS
Converting decimal fractions into binary
representation.
Consider a decimal fraction of the form: 0.d1d2...dn
We want to convert this to a binary fraction of the
form:
0.b1b2...bn (using binary digits instead of decimal
digits)
88.
Algorithm for conversion
LetX be a decimal fraction: 0.d1d2..dn
i = 1
Repeat until X = 0 or i = required no. of binary fractional
digits {
Y = X * 2
X = fractional part of Y
Bi = integer part of Y
i = i + 1
}
89.
EXAMPLE 1
Convert 0.75to binary
X = 0.75 (initial value)
X* 2 = 1.50. Set b1 = 1, X = 0.5
X* 2 = 1.0. Set b2 = 1, X = 0.0
The binary representation for 0.75 is thus
0.b1b2 = 0.11b
EXAMPLE 2
Convert thedecimal value 4.9 into binary
Part 1: convert the integer part into binary: 4 = 100 b
92.
Part 2.
Convert thefractional part into binary using multiplication
by 2:
X = .9*2 = 1.8. Set b1 = 1, X = 0.8
X*2 = 1.6. Set b2 = 1, X = 0.6
X*2 = 1.2. Set b3 = 1, X = 0.2
X*2 = 0.4. Set b4 = 0, X = 0.4
X*2 = 0.8. Set b5 = 0, X = 0.8,
which repeats from the second line above.
93.
Since X isnow repeating the value 0.8,
we know the representation will repeat.
The binary representation of 4.9 is thus:
100.1110011001100...
94.
COMPUTER REPRESENTATION OFFLOATING
POINT NUMBERS
In the CPU, a 32-bit floating point number is
represented using IEEE standard format as follows:
SIGN | EXPONENT | MANTISSA
where SIGN is one bit, the EXPONENT is 8 bits, and
the MANTISSA is 23 bits.
95.
• The mantissarepresents the leading significant bits in
the number.
• The exponent is used to adjust the position of the
binary point (as opposed to a "decimal" point)
• The mantissa is said to be normalized when it is
expressed as a value between 1 and 2. I.e., the mantissa
would be in the form 1.xxxx.
96.
• The leadinginteger of the binary representation is
not stored. Since it is always a 1, it can be easily
restored.
• The "SIGN" bit is used as a sign bit and indicates
whether the value represented is positive or negative
(0 for positive, 1 for negative)
• If a number is smaller than 1, normalizing the
mantissa will produce a negative exponent.
• But 127 is added to all exponents in the floating
point representation, allowing all exponents to be
represented by a positive number.
97.
Example 1. Representthe decimal value 2.5 in 32-
bit floating point format.
2.5 = 10.1
In normalized form, this is: 1.01 * 21
The mantissa: M = 01000000000000000000000
(23 bits without the leading 1)
The exponent: E = 1 + 127 = 128 = 10000000
The sign: S = 0 (the value stored is positive)
So, 2.5 = 0 1000000001 000000000000000000000
98.
Example 2: Representthe number -0.00010011 in
floating point form.
0.00010011 = 1.0011 * 2-4
Mantissa: M = 00110000000000000000000 (23 bits
with the integral 1 not represented)
Exponent: E = -4 + 127 = 01111011
S = 1 (as the number is negative)
Result: 1 01111011 00110000000000000000000
99.
Exercise 1: represent-0.75 in floating point format.
Exercise 2: represent 4.9 in floating point format.