0% found this document useful (0 votes)
34 views57 pages

Data Representation in Computer Systems

Chapter 2 discusses data representation in computer systems, emphasizing the binary system as the fundamental format for processing information. It covers various number systems including binary, octal, decimal, and hexadecimal, along with methods for converting between these systems. Additionally, the chapter introduces binary arithmetic operations and the concepts of fixed and floating-point representations, including the IEEE 754 standard for floating-point numbers.

Uploaded by

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

Data Representation in Computer Systems

Chapter 2 discusses data representation in computer systems, emphasizing the binary system as the fundamental format for processing information. It covers various number systems including binary, octal, decimal, and hexadecimal, along with methods for converting between these systems. Additionally, the chapter introduces binary arithmetic operations and the concepts of fixed and floating-point representations, including the IEEE 754 standard for floating-point numbers.

Uploaded by

itgetachew
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

Chapter 2

Data Representation Inside


Computer System
Introduction Data Representation
A computer is an electronic device i.e. it works using electrical signals.
Electrical signals can represent only two states; on (1) and off (0).
Digital computers are made up of electronic circuits, which have exactly 2 states: on and
off.
The organization of any computer depends considerably on how it represents numbers,
characters, and control information.
So any information that has to be processed by a digital computer has to be converted in to
a format which has two states (0 and 1).
In other word, computer processes any types of data using binary numbers. 2
Numeric Data Representation
Most extensively used number systems in the computer are two types:
1. No-positional number system
It is familiar with Roman Notation System.
In this system, each system represents the same value regardless of its position in the
number.
The symbols are simply added to find out the resultant value of a particular number.
2. Positional number system
In a number system, there are only few symbols which represent different values
depending on their positions.
The total number of different fundamental digits applicable to a number system is
called its radix or base.
The most widely used number system is the positional number system..
Positional Number System

The positional number systems are


Binary Number system(Base 2)
Octal Number system(Base 8)
Decimal Number system(Base 10)
Hexadecimal Number system(Base 16)
Binary Number system
The most popular form which is understood by the computer.
Its radix is 2.
It uses two digits i.e. 0 & 1.
Sometimes it is also called base-two system.
E.g. (110101)2
Octal Numbering System
It was once a popular number base, especially in the digital equipment like old computer
systems.
It is rarely used today
It was developed to provide a short hand way to deal with the long strings of 1s and 0s
created in the binary system.
The radix of octal is 8.
It uses eight digits i.e. 1, 2, 3, 4, 5, 6, and 7. As 23 =8, an octal number is represented by a
set of 3 bits. e.g. (57)8
Decimal Numbering System
It is the most popular form of numbering system which is used by human
being.
Its radix is 10.
It is also called base-ten system or natural number system.
It includes the numbers from 0-9.
Hexadecimal Number System

Hex numbers are very compact

The hexadecimal system is based on the binary system using a Nibble or 4 bit boundary.
The hexadecimal number system uses base 16

Includes only the digits 0 through 9 and the letters A, B, C, D, E, and F for the numbers
starting from 10 to 15 respectively.
Conversion System
Binary To Decimal
Expand the given binary number in the power of 2 .
(Multiply each bit by 2n, where n is the “weight” of the bit)

Ex1: Convert (1001001)2 to decimal


1x26+0x25+0x24+1x23+0x22+0x21+1x20
Ans. = (73)10
Ex2: Convert(10001)2 to decimal?

Ans.= (?)10
Decimal To Binary
Divide the decimal number by 2 until the reminder becomes zero or
impossible to be divided by 2.
Ex 1: Convert (6)10 to binary
Ans. = (110)2

Ex 2: Convert(13)10 to Binary?

Ans. =(?)2
Binary To Octal
Group 3 binary digits together (preferable) but you can go from
2108.
Ex 1. Convert (1001001)2 to octal
1001001=001 001 001
Ans. =(111)8
Ex 2. Convert (101101001)2 to octal

Ans. = (?)8
Octal To Binary
Each Octal digit is converted to 3 binary digits (preferable and simplest
method) but you can go from 8102

Ex 1. Convert (675)8 to binary


(6)8 = (110) 2 (7)8= (111) 2 (5)8= (101) 2
Ans. = (110111101)2

Ex 2. Convert (231)8 to binary


Ans. =(?)2
Binary To Hexadecimal
Group 4 binary digits together (preferable and simplest
method) .but you can go from 21016.
Ex 1. Convert (111100100)2 to hexadecimal
1111001002= (0001 1110 0100) 2
(1 E 4) 16
Ans.= (1E4)16
Ex2. Convert(100111000101)2 to hexadecimal

Ans.=(?)16
Hexadecimal To Binary
Each hexadecimal digit is converted to 4 binary digits(preferable and
simplest method) but you can go from 16102.
Ex1. Convert (234)16 to binary
(2)16 =00102
(3)16= 00112
(4)16=01002
Ans. = (1000110100)2
Ex2. Convert 2AC16 to binary
Ans.= (?)2
Octal To Decimal
Go from 8210 or Expand the octal number in power of 8.

Ex 1. Convert (234)8 to decimal


Ans. = (156)10

Ex2. Convert (101)8 to decimal


Ans. =(?)10
Decimal To Octal
Go from 1028 or divide the decimal number by 8 until the
quotient becomes zero.

Ex 1. Convert (78)10 to base 8 (Octal)


Ans. =(116)8

Ex 2. Convert (16)10 to base 8 (Octal)


Ans. =(?)8
Hexadecimal To Decimal

Go from 16210 or Expand the hex-decimal number


in power of 16.

Ex 1. Convert (A1B) 16 to decimal


Ans. = (2587)10
Ex2. Convert (101)16 to decimal
Ans. =(?)10
Decimal To Hexadecimal

Go from 10216 or divide the decimal number by 16


until the quotient becomes zero.

Ex 1. Convert (30)10 to base 16 (hex-decimal)


Ans.=(1E)16
Ex2. Convert (16)10 to base 16 (hexadecimal)
Ans. =(?)16
Octal To Hexadecimal

Go from 8216 (preferable and simplest method) but you


can go from 81016.

Ex.1. Convert 2358 to hexadecimal


2358=010 011 101
0000 1001 1101
0 9 13=D
Ans. =(?)16
Hexadecimal To Octal

Go from 1628 (preferable and simplest method) but you can


go from 16108
Ex.1. Convert 1A16 to Octal
116=00012
A16=10102
(000 011 010) 2
(0 3 2)8
Ans. =(?)8
Convert Decimal fraction to binary number
A) Convert the integral part of decimal to binary equivalent
steps

1. Divide the decimal number by 2 and store remainders in array.

2. Divide the quotient by 2.

3. Repeat step 2 until we get the quotient equal to zero.

4. Equivalent binary number would be reverse of all remainders of step 1.

22
Cont…
B) Convert the fractional part of decimal to binary equivalent
Steps

1. Multiply the fractional decimal number by 2.

2. Integral part of resultant decimal number will be first digit of


fraction binary number.

3. Repeat step 1 using only fractional part of decimal number and then
step 2.

23
Cont…
C) Combine both integral and fractional part of binary number which is the result.

Example convert (4.45)10 to binary

Step 1: Conversion of 4 to binary

4/2 : Remainder = 0 : Quotient = 2

2/2 : Remainder = 0 : Quotient = 1

1/2 : Remainder = 1 : Quotient = 0

So equivalent binary of integral part of decimal is 100.

24
Cont…
• Step 2: Conversion of 0.45 to binary
 0.45 * 2 = 0.90, Integral part is 0 and fractional part is .90
 0.90 * 2 = 1.80, Integral part is 1 and fractional part is .80
 0.80 * 2 = 1.60, Integral part is 1 and fractional part is .60
 0.60*2=1.20, Integral part is 1 and fractional part is .20
 0.20*2=0.40, Integral part is 0 and fractional part is .40
 0.40*2=0.80, Integral part is 0 and fractional part is .80
 Stop here because, it became redundant.
• So equivalent binary of fractional part of decimal is .011100…
• Step 3: Combined the result of step 1 and 2.
• Final answer can be written as:
• 100 + .011100… = 100.011100..

25
Binary Arithmetic
Binary numbers can be added, subtracted, multiplied and divided like

natural numbers-decimal numbers in which everybody uses them for

day-to-day activities.

 Let’s see how binary arithmetic is performed as the next slide

26
[Link] addition
Rules
0+1=1 E.g. Add (10111)2 and (110101)2
1+1=0 with carry 1 to the next
• Solution
digit
1+1+1=1 with carry 1 to the next • 110101
digit
1+1+1+1=0 with carry 2 to the • +10111
next digit • 1001100

27
[Link] subtraction
Rules Binary subtraction can be also done
1-1=0 using complements.
1-0=1 E.g. (1110-10101)2= (?)2
0-1=1 borrows 1 from the highest digit Solution
E.g. Subtract (10101)2 from (101110)2  Rule: A-B=A+ (-B), where B is 2’s
complement
Solution
 2’s complement=1’s complement + 1
• 101110
 (10101)2 1’s complement= (01010)2
• -10101
and its 2’s complement= (01011)2.
• 11001 Then, apply the rule i.e. (1110 +
01011)2=(11001)2
28
[Link] multiplication

Rules
1x1=1
0x1=0
E.g. Multiply (1111)2 by (111)2
Solution
• 1111
• X 111
• 1111
• 1111
• 1111¬¬¬¬¬¬¬
• (1101001)2
29
[Link] division
 This rule works for a number in which the remainder becomes zero. It may work for non-zero remainder
numbers with some modifications.
 Divide the dividend by the divisor until the remainder becomes zero or less than the divisor (impossible to be
divided).
 When you take two or three etc numbers of a dividend to add on the remainder part, you have to add one zero
(0) or two (00) etc on the quotient respectively.
 When you divide a number having fractional part, don’t worry about the fraction. Divide the number as it is an
integer number.
 But after you complete the division, count the number of fractional digits from left to right to both the dividend
(D) and divisor (Df).
 Then the number of fractional parts of the quotient (Qf) from left to right is equal to the difference between of D
& Df.
 Checking the result
 Dividend=quotient * divisor + remainder
30
Cont…
E.g.1. Divide (100001)2 by (11)2
Solution E.g. 2. Divide (1011.01)2 by (10.1)2

31
Cont…
Note:

If the difference between D & Df

is negative, add zero(s) as many

as the number of the difference

on the right side of the quotient.

 Let’s see it with an example.


32
Fixed- and Floating-point
systems

33
• In representing integer in computers with binary numbers, binary point is
fixed and the operation is known as fixed point arithmetic.
• To represent numbers in such a way that binary point is variable and is
automatically adjusted in computation, floating point representation is
used.
• Since the binary point is said to float (move) numbers are known as
floating point numbers.
• Floating point representation is similar to scientific notation in
decimal number system.

34
• A floating point number ‘a’ can be represented as
a = (sign) * m * be
Where sign can be 0 for positive and 1 for negative.
m  significand or mantissa .This shows the digits that define the
number’s magnitude.
e exponent or characteristic or scale to indicate the position of the
binary point.
b base or radix of the numeration.

Eg: 121.5 = 1.125 *102


101010.111= 1.01010 * 25

35
Binary floating-point numbers in IEEE standard as
follows:
Sign Bit Exponent Mantissa

• where the most significant bit is the sign bit, exponent


is the biased exponent, and mantissa is the significant
minus the most significant bit.

36
Normalized form in binary floating point number

• If the leading digit of mantissa is non zero then the number is said to
be normalized.
• When a number is normalized, its most bit significant bit is 1.
• In the IEEE Single and double precision formats, that bit is called the
“hidden” bit or “implicit” bit.

37
Exponent biasing
• The exponent is biased by (2e-1 ) - 1.
• In the case of single precision representation, e = 8
i.e. = ( 28-1 ) – 1
= 127
• In the case of a double precision representation,
e =11
i.e. = ( 211-1 ) – 1
= 1023

• In the case of single precision, the biased exponent = real exponent + 127
• In the case of a double precision, the biased exponent = real exponent + 1023
38
IEEE 754 standard
• Single precision and double precision representation using binary.

39
Single precision representation (32 bits)
Sign Bit(1 bit) Exponent(8-bits) Mantissa(23-bits)

s = +1 (positive numbers) when the sign bit is 0


s = −1 (negative numbers) when the sign bit is 1

e = Exp + 127 (in other words the exponent is stored with 127 added to it, also
called "biased with 127")

m = Fraction in binary (that is, the significand is the binary number 1 followed
by the radix point followed by the binary bits of Fraction).

40
1. Encode the decimal number −118.625 using the IEEE system.
• First we need to get the sign, the exponent and the fraction. Because it is a
negative number, the sign is "1".
• Now, we write the number (without the sign) using binary notation. The result is
1110110.101.
• Next, let's move the radix point left, leaving only a 1 at its left. That is value of
the number is in the range 1<m<2. This is known as normalization.
• 1110110.101 = 1.110110101 × 26. This is a normalized floating point number.
Since the first digit is now always going to be 1, there is no need to encode this
digit. The mantissa only includes the digits after the point and the leading 1 is
kept as hidden bit. The mantissa is the part at the right of the radix point, filled
with 0 on the right until we get all 23 bits. That is 11011010100000000000000.

41
42
43
Double-precision binary floating-point number-stored in a
64-bit word:

(1 bit) (11-bits) (52-bits)


Sign Bit Exponent Mantissa

•Double precision is essentially the same as single precision,


except that the fields are wider:
•The mantissa is much larger (52-bits), while the exponent is
only slightly larger (11 bits).

44
Signed And Two’s Complement
The conversions we have so far presented have involved only positive
numbers.
To represent negative values, computer systems allocate the high-order bit to
indicate the sign of a value. It is also called the most significant bit.
The remaining bits contain the value of the number.
There are three ways in which signed binary numbers may be expressed:

• Signed magnitude.

• One’s complement.

• Two’s complement.
One’s Complement Representation
One’s complement is another way to represent signed integers.
To encode a negative number, get the binary representation of its
magnitude, then complement each bit.
All the 1 bits is changed to 0 and all the 0 bit is changed to 1 to
get the complement of a number.
One’s Complement of the number is treated as the negative of
that number.
Example:
+5=0 101
-5=1 101=1 010 (One’s complement)
Two’s Complement Representation
Two’s complement is another way to represent signed integers.
To encode a negative number, get the binary representation of its
magnitude, complement each bit, then add 1. (get One’s complement, then
add 1).
Two’s complement of a number is one’s complement of a number+ 1.
Two’s complement of a number is treated as the negative representation of
the number.
Example:
+5 = 0 101
-5=1 101=1 010=1 011
Therefore -5 = 1011(Two’s complement)
Computer Codes or coding method

Computer handles different types of data namely Numeric data,


alphanumeric data, alphabetic data and etc.
Computer system use a binary system for data representation; Two
digits 0 and 1, refer to the presence and absence of electric current or
pulse of light.
 All data and programs that go into the computer are represented in
terms of these numbers.
Computer system encodes the data by means of binary or digital
coding schemes to represent letters, numbers and special characters.
 Some of the commonly used schemes are BCD,EBCDIC, ASCII, and
Unicode.

48
BCD (Binary coded Decimal)
Binary-coded decimal is a system of writing numerals that assigns a four-
digit binary code to each digit 0 through 9 in a decimal (base 10) number.
Simply put, binary-coded decimal is a way to convert decimal numbers into
their binary equivalents.
It is one of the early memory code and with BCD each digit of a decimal
number is converted into its binary equivalent rather than converting the
entire decimal value into binary form.
 In the BCD, with four bits we can represent sixteen numbers (0000 to
1111). But in BCD code only first ten of these are used (0000 to 1001). The
remaining six code combinations i.e. 1010 to 1111 are invalid in BCD.

49
Cont…
E.g.(42)10 is not equal to (101010)2 in BCD but, it is equal to (0100
0010)2. (Here (4)10 = 0100 and (2)10 = 0010)
Therefore

(9)10 = 1001 in BCD


(1)10 = 0001 in BCD
10(1+0)10 = 0001 0000 in BCD
15(1+5)10 = 0001 0101 in BCD

50
Cont…
Since 4 bits is insufficient to represent characters, 6 bits representation
was introduced in BCD coding.
6 bit is enough to represent 10 decimal digits, 26 alphabetic letters and
28 other special characters.
6 bit BCD code can be easily divided into 3 bit groups and each group
can be represented by 1 octal digit.
Thus octal number is used as shortcut notation in BCD coding.
In BCD coding the letter BASE is represented as 110 010 110 001 010
010 110 101
51
Cont…

52
EBCDIC (Extended Binary Coded Decimal Interchange Code)

Using 6 bits BCD can represent only 64 characters. To represent lowercase alphabets
(26), uppercase alphabets (26), decimal numbers (10) and special characters (28+)
BCD coding is not sufficient and was extended from 6 bit to 8 bit. And the new
coding scheme is EBCDIC.

EBCDIC using 8 bits can represent 28 (=256) different characters. EBCDIC 8 bit
coding can be divided into 2 groups of 4 bits. Each group can be represented using 1
hexa decimal digit.

This scheme is developed by IBM and hence mostly used in IBM model computer
and mainframe.
53
Cont…

54
ASCII (American Standard Code For Information Interchange

Short for American Standard Code for Information Interexchange (ASCII).


It is the binary code used in most of the microcomputers. This binary scheme originally
used 7 bits to from a character and so known as ASCII- 7 coding scheme which can
represent only 27 (=128) different characters.
To provide more possible combinations with which to form other characters and
symbols. Extended ASCII or ASCII-8 was introduced.
ASCII-8 use 8 bits to form a character and can represent 28 (=256) different characters.
ASCII is a standard that assigns letters, numbers, and other characters in the 256 slots
available in the 8-bit code. The ASCII decimal (Dec) number is created from binary,
which is the language of all computers.
It is a code for representing 128 English characters as numbers, with each letter
assigned a number from 0 to 127.
ASCII encoding scheme uses hexa decimal for its shortcut notation.
55
Cont…

56
Unicode
Unicode, binary coding scheme uses 2 byte for each character instead

of 1 byte. Unicode can handle 216 (=65,536) character combinations.

BCD, EBCDIC, ASCII 7, and ASCII 8 coding schemes for all

numeric and alphabetic characters are listed below.

57

You might also like