Chapter 2
Chapter 2
systems
02/26/2024
1
Chapter Outlines
Data Representation
Number System
Complements
Fixed and floating point representation
Codes
02/26/2024
2
Data in computers is represented in binary form. The
represented data can be number, text, movie, colour
(picture), sound, or anything else.
Computers understand and respond to only the flow
of electrical charge.
Data representation using the binary number system
02/26/2024
3
1.Non-positional number system
02/26/2024
4
Decimal number system
called the base 10 number system
It has 10 different symbols identified as 0, 1, 2, 3, 4,
5, 6, 7, 8, and 9.
Binary number system
known as base 2 number system,
has two digits 0 and 1.
02/26/2024
5
Octal number system
also called base 8 number system,
has 8 different symbols: 0, 1, 2, 3, 4, 5, 6, and 7.
Hexadecimal number system
also called base 16 number system,
has 16 different symbols 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A,
B, C, D, E, and F.
It is used to write binary numbers in short form.
02/26/2024
6
1. Conversion from Decimal to Base m
Step 1: Divide the given decimal number by m (the
desired base).
The result will have a quotient and a remainder.
Step 2: Repeat step 1 until the quotient becomes 0,
the quotient is 0 whenever the number < m.
Step 3: Collect and arrange the remainders in such a
way that the first remainder is the least significant
digit and the last remainder is the most significant
digit.
02/26/2024
7
Eg: Convert the decimal number 47 into binary, octal,
and hexadecimal.
a. Conversion to binary divide by 2.
02/26/2024
8
Hence the result is 1011112.
02/26/2024
9
Therefore, 47 = 578
c. Conversion to hexadecimal
numbers are divided by 16.
02/26/2024
10
2. Conversion from Base m to Decimal
Step 1: Multiply each digit by its positional value.
Step 2: Calculate the sum of the products you get in
step 1.
Example 1: Convert the binary number 110001 into
decimal.
1100012 = (1 × 25) + (1 × 24) + (0 × 23) + (0 × 22)
+
(0 × 21) + (1 × 20) = (1 × 32) + (1 × 16) + (0 × 8) +
(0 ×
4) + (0 × 2) + (1 × 1) = 32 + 16 + 0 + 0 + 0 + 1 = 49
Therefore, 1100012 = 49.
02/26/2024
11
Example 2: Convert the octal number 22 into decimal.
228 = (2 × 81) + (2 × 80) =
(2 × 8) + (2 × 1) = 16 + 2 = 18
Therefore, 228 = 18
Example 3: Convert the hexadecimal number D1 into
decimal.
D116 = (13 × 161) + (1 × 160)
Therefore, D116 = 209
02/26/2024
12
3. Conversion from Binary to Octal
It is possible to use decimal number system as an
intermediate base to convert from any base to any
other base. However, for conversion from binary to
octal or vice versa, there is a very simple method.
.
02/26/2024
13
Step 1: Group the binary digits (bits) starting from
the rightmost dig into 3 bits.
If the remaining bits at the leftmost position are fewer than 3,
add 0s at the front.
Step 2: For each 3-bit binary string, find the corresponding
octal number
Example: Convert the binary numbers 110011 and
1101111 to octal.
02/26/2024
14
The bits are grouped in three with the equivalent octal
digit given below the three bit group.
Thus, 1100112 = 638
The result is 11011112 = 1578.
4. Conversion from Octal to Binary
Step 1: For each octal digit, find the equivalent three
digit binary number.
Step 2: If there are leading 0s for the binary equivalent of
the leftmost octal digit, remove them.
02/26/2024
15
Example: Find the binary equivalent for the octal
numbers 73 and 160.
02/26/2024
16
Therefore, 738 = 1110112 and
Thus, 1608 = 11100002
02/26/2024
17
Step 1: Starting from the rightmost bit, group the bits in 4. If
the remaining bits at the leftmost position are fewer than 4,
add 0s at the front.
Step 2: For each 4-bit group, find the corresponding
hexadecimal number.
Example: Convert the binary numbers 10011110 to
hexadecimal.
02/26/2024
18
Therefore, 100111102 = 9E16
6. Conversion from Hexadecimal to Binary
Step 1: For each hexadecimal digit, find the
equivalent four digit binary number.
Step 2: If there are leading 0s for the binary
equivalent of the leftmost hexadecimal digit, remove
them.
02/26/2024
19
Example: Find the binary equivalents for the
hexadecimal numbers 1C and 823
02/26/2024
20
7. Conversion from Octal to Hexadecimal of Vice
Versa
The decimal number system can be used as an
intermediate conversion base.
second alternative is using the binary number
system as an intermediate base.
Step 1: Convert the given number into binary.
Step 2: Convert the binary number you got in step 1
into the required base.
02/26/2024
21
Example : Convert the octal number 647 to hexadecimal.
02/26/2024
22
8. Conversion from Octal to Hexadecimal or Vice
Versa
Example 2: Find the octal equivalent for the
hexadecimal number 3D5
02/26/2024
23
If the numbers we want to represent are only positive
(unsigned) integers,
simply represent the unsigned integer with its binary
value.
Signed integersare represented in three ways
these are sign magnitude, One’s complement
and Two’s complement.
02/26/2024
24
Sign-magnitude representation is the easiest way to
represent signed integers.
Treat the most significant bit as a sign bit the
remaining bits are used to represent the magnitude of
the integer.
A 0 on the sign bit indicates the integer is positive
and a 1 indicates the integer is a negative.
As example, the sign-magnitude representation
of 79 and -79 in 8 bits are 01001111 and 11001111
respectively.
02/26/2024
25
Every number system has two complement systems.
For a given base n the complements are n’s complement and
(n-1)’s complement.
Thus, in decimal numbers system (base 10), the complement
systems are 10’s complement and 9’s complement.
Similarly, in binary number system, the complements are 2’s
complement and 1’s complement.
The one’s complement of a binary integer is found by inverting
all 0s to 1s and all 1s to 0s. In one’s complement integer
representation, the negative of an integer is represented by its
complement.
02/26/2024
26
For example,
The one’s complement representation of 16 and -16
in 8 bits are:
16= 00010000 and
-16= 11101111.
For 8-bits number system:
Largest Positive Number: 0 1111111= +(127)10
Largest Negative Number: 1 0000000 =-(127)10
For 3-bits system:
+5 = 0101
-5 = 1010
02/26/2024
27
The two’s complement of an integer is found by
adding 1 to its one’s complement
Example, two’s complement representation of 19
and -19 in 8 bits are 00010011 and 11101101
respectively.
(-5) in 2’s complement
(+5) = 0101
1’s complement of (+5) = 1010
Add 1 in 1010: 1010+1 = 1011
Therefore (-5) = 1011
02/26/2024
28
Floating Point representation of a number has two parts. The first
part represents a signed, fixed-point number called the mantissa.
The second part designates the position of the decimal (or binary)
point and is called the exponent.
The memory location is divided into three fields, or blocks of bits.
One field, the first bit, is reserved for sign of the number (usually 0
for + and 1 for - ); a second field, for the exponent of the number;
and last field, for the mantissa of the number.
02/26/2024
29
If the binary number 0.101 x 24 (unsigned)is stored in
a format that allows 8 bits for the mantissa and 4 bits
for the exponent, it would be stored as a 12-bit
number as shown below.
02/26/2024
30
Binary Coded Decimal (BCD)
There are many ways of representing numerical data (digits 0
– 9) in binary form.
One way is simply to write the numbers to the base 2. This is
called straight binary coding.
Another way is to encode decimal digits.
The BCD (Binary Coded Decimal), also
called packed decimal, in order to have
representations for the ten digits of the
decimal number system, we need a four bit
string.
Weights are: 8, 4, 2, and 1 from MSB to LSB
(called 8-4-2-1 code).
02/26/2024
31
Used to encode numbers for output to numerical displays
Used in processors that perform decimal arithmetic.
BCD code provides an excellent interface to binary systems:
– Keypad inputs
– Digital readouts
Example: (9750)10 = (1001 0111 0101 0000)BCD
9 7 5 0
Note: 1010, 1011, 1100, 1101, 1110, and 1111 are INVALID
CODE!
Exercise: Convert Decimal to BCD Convert BCD-to-Decimal
(a) 35 (a) 10000110
(b) 98 (b) 001101010001
(c) 170 (c) 1001010001110000
(d) 2469
02/26/2024
32
Alphanumeric codes are used to represent numbers
and alphabetic characters.
Examples: letters of the alphabet, the ten digits (0
through 9), punctuation marks, Whitespace etc.
(odd/even parity).
02/26/2024
34
02/26/2024
35
Another character encoding system is the EBCDIC.
It uses 8 bits per character (and a ninth parity bit),
02/26/2024
36
In order to be compatible with older systems that
didn't support Unicode, Encoding Forms were
defined by the Unicode Consortium to be a
representation of the character in bits.
The number indicates the encoding form that is to be
used: UTF-8 indicates an 8-bit encoding form,
while UTF-16 indicates a 16-bit encoding form.
02/26/2024
37