You are on page 1of 60

Chapter 2

Data Representation in Computer


Systems
2.1 Introduction
• The organization of any computer depends considerably on
how it represents numbers, characters, and control
information.
• A bit is the most basic unit of information in a
computer.
 It is a state of “on” or “off” in a digital circuit.
 Sometimes these states are “high” or “low” voltage
instead of “on” or “off..”
• A byte is a group of eight bits.
 A byte is the smallest possible addressable unit of
computer storage.
 The term, “addressable,” means that a particular byte can
2
be retrieved according to its location in memory.
Cont….

• A word is a contiguous group of bytes.


 Words can be any number of bits or bytes.
 Word sizes of 16, 32, or 64 bits are most common.
 In a word-addressable system, a word is the smallest
addressable unit of storage.
• A group of four bits is called a nibble (or nybble).
 Bytes, therefore, consist of two nibbles: a “high-order
nibble,” and a “low-order” nibble.

3
2.2 Data Types

What is data type in programming?


 It is the classification of a particular type of information in
to different types.

What is data type in digital computer?


The data types found in the registers of digital computer
may be classified as one of the following categories:-
1. Numbers used in arithmetic computations.
2. Letters of the alphabet used in data processing,
and
3. Other discrete symbols used for specific purpose.

4
Cont….

• All the types of data except binary numbers are represented


as binary coded form in register.
• This is because registers are made up of flip-flop.

What is flip-flop?
• Flip-flops are a binary cell or a two state device that stores
only binary numbers(0’s and 1’s)
• Everything a computer does is broken down into a series of
0s and 1s.

5
2.3 Number Systems

• Number systems are organized ways to represent numbers.


• A number system of base ,or radix ‘r’ is a system that uses a
distinct symbols for r digits.
 Binary- base(2) 0,1
 Octal- base(8) 0-7
 Decimal – base(10) 0-9
 Hexadecimal- base(16) 0-9,A,B,C,D,E,F
 Each number in one system has a corresponding number in
another.

6
Cont….

• Number System Conversion Table

7
Binary Number Systems

• It referred to as base 2 numbering system


• Used to represent every piece of data stored in a computer:
all of the numbers, letters, and instructions.

01011001 = 89
8
Binary Base 10
Conversion from one base to Another

 Conversion from Decimal to Binary, octal &Hexadecimal


1. (37)(10) = ………(2)
2. (15.75)(10) = ………(2)
3. (37)(10) = ………(8)
4. (15.75)(10) = ………(8)
5. (37)(10) = ………(16)
6. (15.75)(10) = ………(16)
 Conversion from Binary to Decimal
1. 1001001)(2)= ……..(10)
9
2. (11001.11)(2)= ……..(10)
Cont….

 Conversion from octal & Hexadecimal to Binary


1. (457)(8)= ……..(2)
2. (34.25)(8)= ……..(2)
3. (3AF.5)(16)= ……..(2)
4. (A0C)(16)= ……..(2)

10
2.4 Complements

11
Cont….

(r’s) complement
•The r’s complement of an n-digit number N in base r is :
•It also obtained by adding 1 to (r-1)’s complement. So

e.g The 10’s complement of 5690 is:


r = 10 , N= 5690 n=4
Ans: 4310

e.g Find the 2’s complement of 1101.


12
Cont….

The (r-1)’s complement


• For any number N in base r with number of digits n, the
(r-1)’s complement is : (rn -N) -1
e.g The 7’s complement of octal no. 5674 is:
n= 4 , N = 5674 , r=8
= (rn -N) -1 = 84 – 5674 – 1
= (4096)10 – 5674 – 1
= 10000 – 5674 – 1
=7777– 5674
= 2103
Find the 8’s Complement of 5674
13
2.5 Fixed point Representation

• 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.
 The high-order bit is the leftmost bit in a byte. It is also
called the most significant bit.
• In ordinary arithmetic, a negative number is indicated by
minus sign and a positive number by a plus sign. But in
computer system we use 0’s and 1’s.
• The storage location can be as small as an 8-bit byte or as
large as several words, depending on the programming
language and the computer system. 14
Cont….

• There are three ways in which signed binary numbers


may be expressed:
 Sign magnitude,
 One’s complement and
 Two’s complement.
• In an 8-bit word, signed magnitude representation
places the absolute value of the number in the 7 bits to
the right of the sign bit.

15
Sign-magnitude Representation

• For example, in 8-bit sign magnitude, positive 3 is:


00000011
• Negative 3 is: 10000011
Example 1: Represent -13 using 5-bits sign magnitude
representation
first we convert 13 to binary i.e 01101
Now -13 = 11101
Example 2: Represent –24 using 8-bits sign magnitude
representation
24=…………….
-24=……………
16
• Addition is the same as ordinary arithmetic
Cont….

• In Binary addition you need to know only four rules:


0+0= 0 0+1= 1
1+0= 1 1 + 1 = 10
• The simplicity of this system makes it possible for
digital circuits to carry out arithmetic operations.

Let’s see how the addition rules work with signed


magnitude numbers . . .

17
Cont….

• Example:
 Using signed magnitude
binary arithmetic, find the
sum of 75 and 46.
• First, convert 75 and 46 to
binary, and arrange as a sum, but
separate the (positive) sign bits
from the magnitude bits.

18
Cont….

• Example:
 Using signed magnitude
binary arithmetic, find the
sum of 75 and 46.
• Just as in decimal arithmetic, we
find the sum starting with the
rightmost bit and work left.

19
Cont….

• Example:
 Using signed magnitude
binary arithmetic, find the
sum of 75 and 46.
• In the second bit, we have a
carry, so we note it above the
third bit.

20
Cont….

• Example:
 Using signed magnitude
binary arithmetic, find the
sum of 75 and 46.
• The third and fourth bits also
give us carries.

21
Cont….

• Example:
 Using signed magnitude binary
arithmetic, find the sum of 75
and 46.
• Once we have worked our way
through all eight bits, we are done.

In this example, we were careful to pick two values whose


sum would fit into seven bits. If that is not the case, we
have a problem.

22
Cont….

• Example:
 Using signed magnitude binary
arithmetic, find the sum of 107
and 46.
• We see that the carry from the
seventh bit overflows and is
discarded, giving us the erroneous
result: 107 + 46 = 25.

23
Cont….

• The signs in signed magnitude


representation work just like the
signs in pencil and paper
arithmetic.
 Example: Using signed
magnitude binary arithmetic,
find the sum of - 46 and - 25.
• Because the signs are the same, all we do is add the
numbers and supply the negative sign when we are
done.

24
Cont….

• Mixed sign addition (or


subtraction) is done the same way.
Example: Using signed
magnitude binary arithmetic, find
the sum of 46 and - 25.
• The sign of the result gets the sign
of the number that is larger.

25
One’s Complement Representation

• In one’s complement representation, all positive integers are represented in their


correct binary format. The difference lies in the representation of negative
numbers.
• Each 0 is transformed into 1 and each 1 into 0.
Example 1. Represent –3 using One’s complement representation with word size 4
3 = 0011
-3=1100
Example 2: Add –7 and 3 with word size 8
- 7 is 11111000
+ 3 is 00000011
the sum is ( 11111011)
Example 3. Add -4 and +6 with word size 8
- 4 is 11111011
+ 6 is 00000110
the sum is (1) 00000001 the one in the parenthesis is the external carry.

26
Two’s complement representation

• To express a value in two’s complement:


 If the number is positive, just convert it to binary and
you’re done.
 If the number is negative, find the one’s complement of
the number and then add 1.
• Example:
 In 8-bit one’s complement, positive 3 is: 00000011
 Negative 3 in one’s complement is: 11111100
 Adding 1 gives us -3 in two’s complement form:
11111101.

27
Cont….

• With two’s complement arithmetic, all we do is add our two


binary numbers. Just discard any carries emitting from the
high order bit.

 Example: Using two’s


complement binary
arithmetic, find the sum of
48 and - 19.

We note that 19 in one’s complement is: 00010011,


so -19 in one’s complement is: 11101100,
and -19 in two’s complement is: 11101101.

28
Cont….

• When we use any finite number of bits to represent a


number, we always run the risk of the result of our
calculations becoming too large to be stored in the
computer.
• While we can’t always prevent overflow, we can always
detect overflow.
• In complement arithmetic, an overflow condition is easy
to detect.

29
2.6 Other Binary Codes

• In previous sections we introduced the most common types


of binary-coded data found in digital computers.
• Other binary codes for decimal numbers and alphanumeric
characters are sometimes used.
• Digital Computers also employ other binary codes for special
applications.
BCD (Binary Coded Decimal)
EBCDIC (Extended Binary Coded Decimal
Interchange Code )
ASCII (American Standard Code for Information
Interchange)

30
BCD( Binary Coded Decimal)
• There are two types of BCD coding techniques used
before.
a) 4 bits BCD and
b) 6 bits BCD
BCD (4 -bits)
• The 4 bit BCD, which represent any digit of decimal number by four
bits of binary numbers.
• If you want to represent 219 using 4 bit BCD you have to say 0010
0001 1001
BCD(6-bit)
• It uses 6-bits to code a Character (2 for zone bit and 4 for
digit bit)
• It can represent 26 = 64 characters (10 digits, 26 capital 31
characters and some other special characters).
Cont….

• Some Coding Examples


Character zone zone (2 Bit) Digit (4 Bit)
0-9 0
0-9 A-I
3 1-9 J-R
2 1-9
S-Z 1 2-9
Example 1. Represent Character A using 6-bits BCD
A 11 0001
A = 110001
32
EBCDIC(Extended Binary Coded Decimal
Interchange Code)
• It is an 8-bit coding scheme: (00000000 – 11111111)
• It accommodates to code 28 or 256 different characters
• It is a standard coding scheme for the large computers.
• Coding Example:
Character zone (4 Bit) Digit (4 Bit)
0-9 15 0-9
a-i 8 1-9
j-r 9 1-9
s-z 10 2-9
A-I 12 1-9
J-R 13 1-9
S-Z 14 2-9
Example 1. Represent Character A using EBCIDIC
A 1100 0001 33
A= 1100001
ASCII(American Standard Code for
Information Interchange Code)

• Used widely before the introduction of ASCII-8 (the Extended ASCII)


• Uses 7 bits to represent a character;
• With the seven bits, 27(or 128) different characters can be coded
(0000000-1111111)
• Coding examples:
Character zone (3 bit) digit (4 bit)
0-9 3 0-9
A-O 4 1-15
P-Z 5 0-10
a- o 6 1-15
p- z 7 0-10
Example 1. Represent Character A using ASCII
A 100 0001
A= 1000001

34
Cont….

*Unicode
•Both EBCDIC and ASCII were built around the Latin
alphabet, they are restricted in their abilities to provide data
representation for the non-Latin alphabets.
•Is a new international information exchange code.
•Because the base coding of Unicode is 16 bits, it has the
capacity to encode the majority of characters used in every
language of the world.
•Many of today’s systems embrace Unicode, a 16-bit
system that can encode the characters of every language
in the world.
 The Java programming language, and some operating systems now
35
use Unicode as their default character code.
2.7 Error Detection and Correction

• It is physically impossible for any data recording or


transmission medium to be 100% perfect 100% of the time
over its entire expected useful life and also impossible to
detect or correct 100% of all errors that could occur in
a medium.
• Error rates increase in direct proportion to the number of
bits per second transmitted, or the number of bits per
square millimeter of magnetic storage.
• Thus, error detection and correction is critical to accurate
data transmission, storage and retrieval.

36
Cont….

• Checksums are used in a wide variety of coding systems,


from bar codes to International Standard Book Numbers
(ISBNs).
• Checksums are self-checking codes that will quickly
indicate whether the preceding digits have been misread.
• Longer data streams require more economical and
sophisticated error detection mechanisms.
• Check digits, appended to the end of a long number can
provide some protection against data input errors.

37
Cont….

CRC (Cyclic redundancy check) – also called polynomial code.


•A type of checksum used primarily in data communications that
determines whether an error has occurred within a large block or
stream of information bytes.
•The larger the block to be checked, the larger the checksum must be
to provide adequate protection.
•Checksums and CRCs are examples of systematic error detection.
•In systematic error detection a group of error control bits is
appended to the end of the block of transmitted data.
– This group of bits is called a syndrome.

38
Cont….

Arithmetic Modulo 2
•Arithmetic modulo 2 uses two binary operands with no borrows or
carries.

•CRCs are polynomials over the modulo 2 arithmetic field.

39
Cont….

• Find the quotient and remainder


when 1111101 is divided by 1101 in
modulo 2 arithmetic.
– As with traditional division,
we note that the dividend is
divisible once by the divisor.
– We place the divisor under the
dividend and perform modulo
2 subtraction.

40
Cont….

• Find the quotient and remainder


when 1111101 is divided by 1101 in
modulo 2 arithmetic…
– Now we bring down the next
bit of the dividend.
– We see that 00101 is not
divisible by 1101. So we place
a zero in the quotient.

41
Cont….

• Find the quotient and remainder


when 1111101 is divided by 1101 in
modulo 2 arithmetic…
– 1010 is divisible by 1101 in
modulo 2.
– We perform the modulo 2
subtraction.

42
Cont….

• Find the quotient and remainder


when 1111101 is divided by 1101 in
modulo 2 arithmetic…
– We find the quotient is 1011,
and the remainder is 0010.
• This procedure is very useful to us
in calculating CRC syndromes.

*Find the quotient and remainder


when 10010112 is divided by 10112.

Note: The divisor in this example corresponds


to a modulo 2 polynomial: X 3 + X 2 + 1.
43
Cont….

• Suppose we want to transmit the


information string: 1111101.
• The receiver and sender decide to use
the (arbitrary) polynomial pattern (p),
1101.
• The information string is shifted left
by one position less than the number
of positions in the divisor.(The binary
data is augmented by adding p-1 zeros in the
end of the data )
• The remainder is found through
modulo 2 division (at right) (Here,the
remainder is the actual CRC checksum.)

44
Cont….

• Add the remainder to the information


string I, giving the message M:
1111101000 + 111 = 1111101111(M)
*M is decoded and checked by the
message receiver using the reverse
process.
• If no bits are lost or corrupted, dividing
the received information string by the
agreed upon pattern will give a
remainder of zero.
• Real applications use longer
polynomials to cover larger information
strings.

45
Cont….

E.g. Using the CRC polynomial 1011, compute the


CRC code word for the information word,
10010112.Check the division performed at the
receiver.

46
Cont….

• Data transmission errors are easy to fix once an error is


detected.
– Just ask the sender to transmit the data again.
• In computer memory and data storage, however, this
cannot be done.
– Too often the only copy of something important is in
memory or on disk.
• Thus, to provide data integrity over the long term, error
correcting codes are required.

47
Cont….

• Hamming codes and Reed-Soloman codes are two


important error correcting codes.
• Reed-Soloman codes are particularly useful in correcting
burst errors that occur when a series of adjacent bits are
damaged.
– Because CD-ROMs are easily scratched, they employ a type
of Reed-Soloman error correction.
• Because the mathematics of Hamming codes is much
simpler than Reed-Soloman, we discuss Hamming codes
in detail.

48
Cont….

• Hamming codes are code words formed by adding


redundant check bits, or parity bits, to a data word.
• The Hamming distance between two code words is the
number of bits in which two code words differ.
This pair of bytes has a
Hamming distance of 3:

• The minimum Hamming distance for a code is the smallest


Hamming distance between all pairs of words in the code.

49
Cont….

• With n-bit code words, we have 2 n possible code words


consisting of 2 m data bits (where n = m + r).
• We can find easily the Check bit using the following
inequality.
=> (m + r + 1)  2 r
– This inequality gives us a lower limit on the number of
check bits that we need in our code words.

50
Cont….

• Suppose we have data words of length m = 4. Then:


(4 + r + 1)  2 r
implies that r must be greater than or equal to 3.
• This means to build a code with 4-bit data words that
will correct single-bit errors, we must add 3 check bits.

51
Cont….

The Hamming algorithm provides a straightforward method for


designing codes to correct single bit errors. To construct error
correcting codes for any size memory word, we follow these
steps:
Steps
1.Determine the number of check bits, r, necessary for the code
and then number the n bits (where n=m+r), right to left, starting
with 1 (not 0)
2.Each bit whose bit number is a power of 2 is a parity bit—the
others are data bits.
3.Assign parity bits to check bit positions as follows: Bit b is
checked by those parity bits b1 b2, . . . , bj.
52
Cont….

• Suppose we have data words of length m = 8. Then:


(8 + r + 1)  2 r
implies that r must be greater than or equal to 4.
• This means to build a code with 8-bit data words that will
correct single-bit errors, we must add 4 check bits,
creating code words of length 12.
• So how do we assign values to these check bits?

53
Cont….

• With code words of length 12, we observe that each of the


digits, 1 though 12, can be expressed in powers of 2. Thus:
1 = 20 5 = 22 + 2 0 9 = 23 + 2 0
2 = 21 6 = 22 + 2 1 10 = 2 3 + 2 1
3 = 21+ 2 0 7 = 22 + 21 + 2 0 11 = 2 3 + 2 1 + 2 0
4 = 22 8 = 23 12 = 2 3 + 2 2
1 (= 20) contributes to all of the odd-numbered digits.
2 (= 21) contributes to the digits, 2, 3, 6, 7, 10, and 11.
. . . And so forth . . .

• We can use this idea in the creation of our check bits.

54
Cont….

 Using our code words of length 12, number each bit


position starting with 1 in the low-order bit.
 Each bit position corresponding to an even power of
2 will be occupied by a check bit(parity bit).
 These check bits contain the parity of each bit
position for which it participates in the sum.

55
Cont….

• Suppose the data to be transmitted is 11010110.

What are the values for the other parity bits?


(Assuming even parity bit)

56
Cont….

• Since 1 (= 20) contributes to the digits 3, 5, 7, 9, and 11


– Bit 1checks the digits, 3, 5, 7, 9, and 11, so its value is 1.
– Bit 2 will contain the parity for bits 3, 6, 7, 10, and 11, so its value is 0.
– Bit 4 checks the digits, 5, 6, 7, and 12, so its value is 1.
– Bit 8 checks the digits, 9, 10, 11, and 12, so its value is also 1.
– The final code word is:-

• Using the Hamming algorithm, we can not only detect single bit errors in
this code word, but also correct them!

57
Cont….

• Suppose an error occurs in bit 5, as shown above. Our


parity bit values are:
– Bit 1 checks digits, 3, 5, 7, 9, and 11. Its value is 1, but
should be zero.
– Bit 2 checks digits 3, 6, 7, 10, and 11. The zero bit is
correct.
– Bit 4 checks digits, 5, 6, 7, and 12. Its value is 1, but should
be zero.
– Bit 8 checks digits, 9, 10, 11, and 12. This bit 1 is correct.

58
Cont….

• We have erroneous bits in positions 1 and 4.


• With two parity bits that don’t check, we know that the
error is in the data, and not in a parity bit.
• Which data bits are in error? We find out by adding the
bit positions of the erroneous bits.
• Simply, 1 + 4 = 5. This tells us that the error is in bit 5.
If we change bit 5 to a 1, all parity bits check and our
data is restored.
59
Cont….

e.g. Using the Hamming code and even parity,


encode the 8-bit ASCII character K. (01001011)

*Let’s introduce an error in which its codeword is


010111010110.

60

You might also like