0% found this document useful (0 votes)
11 views38 pages

Data Representation and Computer Arithmetic

Chapter 4 discusses data representation in computing, introducing bits, bytes, and words as fundamental units. It explains various number systems (decimal, binary, octal, hexadecimal) and their arithmetic operations, along with methods for converting between these systems. Additionally, it covers coding methods like EBCDIC, BCD, ASCII, and Unicode for representing characters in computer systems.

Uploaded by

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

Data Representation and Computer Arithmetic

Chapter 4 discusses data representation in computing, introducing bits, bytes, and words as fundamental units. It explains various number systems (decimal, binary, octal, hexadecimal) and their arithmetic operations, along with methods for converting between these systems. Additionally, it covers coding methods like EBCDIC, BCD, ASCII, and Unicode for representing characters in computer systems.

Uploaded by

fikadus794
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 38

Chapter 4

Data Representation and


Computer Arithmetic
Units of Data Representation

 BIT:
 Bits are the smallest units and can convey only two possible states 0 or 1;
 Bit stands for Binary digits;
 A bit is a single element in the computer, on a disk that stands for either “ON”
indicating 1 or “OFF” indicating 0;
 BYTE:
 Bits can be organized into large units to make them represent more and meaningful
information.
 1byte = 8 bits.
 a single byte is 28 or 256 possible combinations.
 Each byte can represent a character (a character is either a letter, a number or a
special symbol such as +,-,?,*, $, etc).
 WORD:
 number of bits that a computer process at a time
Concept of Number Systems and Binary Arithmetic

 A number system defines a set of values used to represent quantity.


 There are various number systems e.g. decimal, binary, octal, hexadecimal, etc each
differs one another by the number of symbols used in the system.
 Each numbering system used different symbols to represent a given quantity.

 For a computer, everything is a number whether it may be numbers, alphabets,


punctuation marks, its own instructions, etc.
 The number systems that are generally used by computers are: decimal,
binary, octal, and hexadecimal.
Decimal Number System
 Base (also called radix) = 10
 10 digits { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }
 Digit Position
 Integer & fraction 2 1 0 -1 -2
 Digit Weight 5 1 2 7 4
 Weight = (Base) Position
 Magnitude 100 10 1 0.1 0.01
 Sum of “Digit x Weight”
 Formal Notation
500 10 2 0.7 0.04

d2*B2+d1*B1+d0*B0+d-1*B-1+d-2*B-2

(512.74)10
Octal Number System
 Base = 8
 8 digits { 0, 1, 2, 3, 4, 5, 6, 7 }
 Weights
 Weight = (Base) Position 64 8 1 1/8 1/64
 Magnitude 5 1 2 7 4
 Sum of “Digit x Weight” 2 1 0 -1 -2
 Formal Notation 2 1 0 -1 -2
5 *8 +1 *8 +2 *8 +7 *8 +4 *8

=(330.9375)10
(512.74)8
Binary Number System
 Base = 2
 2 digits { 0, 1 }, called binary digits or “bits”
 Weights
4 2 1 1/2 1/4
 Weight = (Base) Position
 Magnitude 1 0 1 0 1
 Sum of “Bit x Weight” 2 1 0 -1 -2
 Formal Notation 2 1 0
1 *2 +0 *2 +1 *2 +0 *2 +1 *2
-1 -2

 Groups of bits 4 bits = Nibble


=(5.25)10
8 bits = Byte
(101.01)2
1011

11000101
Hexadecimal Number System
 Base = 16
 16 digits { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F }
 Weights
 Weight = (Base) Position 256 16 1 1/16 1/256

 Magnitude 1 E 5 7 A
 Sum of “Digit x Weight” 2 1 0 -1 -2
 Formal Notation 2 1 0 -1 -2
1 *16 +14 *16 +5 *16 +7 *16 +10 *16

=(485.4765625)10
(1E5.7A)16
The Power of 2

n 2n n 2n
0 20=1 8 28=256
1 21=2 9 29=512
2 22=4 10 210=1024 Kilo

3 23=8 11 211=2048
4 24=16 12 212=4096
5 25=32 20 220=1M Mega

6 26=64 30 230=1G Giga

7 27=128 40 240=1T Tera


Addition
 Decimal Addition

1 1 Carry
5 5
+ 5 5

1 1 0
= Ten ≥ Base
 Subtract a Base
Binary Addition
 Column Addition

1 1 1 1 1 1
1 1 1 1 0 1 = 61
+ 1 0 1 1 1 = 23

1 0 1 0 1 0 0 = 84

≥ (2)10
Binary Subtraction
 Borrow a “Base” when needed

1 2 = (10)2
0 2 2 0 0 2
1 0 0 1 1 0 1 = 77
− 1 0 1 1 1 = 23

0 1 1 0 1 1 0 = 54
Binary Multiplication
 Bit by bit

1 0 1 1 1
x 1 0 1 0
0 0 0 0 0
1 0 1 1 1
0 0 0 0 0
1 0 1 1 1

1 1 1 0 0 1 1 0
Number Base Conversions
Evaluate
Magnitude
Octal
(Base 8)

Evaluate
Magnitude
Decimal Binary
(Base 10) (Base 2)

Hexadecimal
(Base 16)
Evaluate
Magnitude
Decimal (Integer) to Binary
Conversion
 Divide the number by the ‘Base’ (=2)
 Take the remainder (either 0 or 1) as a coefficient
 Take the quotient and repeat the division

Example: (13)10
Quotient Remainder Coefficient
13/ 2 = 6 1 a0 = 1
6 /2= 3 0 a1 = 0
3 /2= 1 1 a2 = 1
1 /2= 0 1 a3 = 1
Answer: (13)10 = (a3 a2 a1 a0)2 = (1101)2

MSB LSB
Decimal (Fraction) to Binary
Conversion
 Multiply the number by the ‘Base’ (=2)
 Take the integer (either 0 or 1) as a coefficient
 Take the resultant fraction and repeat the multiplication

Example: (0.625)10
Integer Fraction Coefficient
0.625 * 2 = 1 . 25 a-1 = 1
0.25 * 2 = 0 . 5 a-2 = 0
0.5 *2= 1 . 0 a-3 = 1
Answer: (0.625)10 = (0.a-1 a-2 a-3)2 = (0.101)2

MSB LSB
Decimal to Octal Conversion
Example: (175)10
Quotient Remainder Coefficient
175 / 8 = 21 7 a0 = 7
21 / 8 = 2 5 a1 = 5
2 /8= 0 2 a2 = 2
Answer: (175)10 = (a2 a1 a0)8 = (257)8

Example: (0.3125)10
Integer Fraction Coefficient
0.3125 * 8 = 2 . 5 a-1 = 2
0.5 *8= 4 . 0 a-2 = 4
Answer: (0.3125)10 = (0.a-1 a-2 a-3)8 = (0.24)8
Binary − Octal Conversion
 8 = 23 Octal Binary

 Each group of 3 bits represents an octal 0 000


digit 1 001
2 010
Assume Zeros
Example: 3 011

( 1 0 1 1 0 . 0 1 )2 4 100
5 101
6 110
( 2 6 . 2 )8 7 111

Works both ways (Binary to Octal & Octal to Binary)


Binary − Hexadecimal Conversion
Hex Binary
 16 = 24 0 0000
1 0001
 Each group of 4 bits represents a
2 0010
hexadecimal digit 3 0011
4 0100
5 0101
Assume Zeros 6 0110
Example: 7 0111
8 1000
( 1 0 1 1 0 . 0 1 )2 9 1001
A 1010
B 1011
C 1100
D 1101
(1 6 . 4 )16 E 1110
F 1111

Works both ways (Binary to Hex & Hex to Binary)


Octal − Hexadecimal Conversion
 Convert to Binary as an intermediate step

Example:
( 2 6 . 2 )8

Assume Zeros Assume Zeros

( 0 1 0 1 1 0 . 0 1 0 )2

(1 6 . 4 )16

Works both ways (Octal to Hex & Hex to Octal)


Decimal, Binary, Octal and
Hexadecimal
Decimal Binary Octal Hex
00 0000 00 0
01 0001 01 1
02 0010 02 2
03 0011 03 3
04 0100 04 4
05 0101 05 5
06 0110 06 6
07 0111 07 7
08 1000 10 8
09 1001 11 9
10 1010 12 A
11 1011 13 B
12 1100 14 C
13 1101 15 D
14 1110 16 E
15 1111 17 F
CODING METHODS
 There are a lot of ways to represent, numeric, alphabetic, and
special characters in computer’s internal storage area
 It is possible to represent any of the character in our language in
a way as a series of electrical switches in arranged manner.
 These switch arrangements can therefore be coded as a series of
equivalent arrangements of bits.
 There are different coding systems that convert one or more
character sets into computer codes.
 Some are: EBCDIC, BCD, ASCII-7 & ASCII-8, Unicode, etc.
 In these encodings, binary coding schemes separate the
characters, known as character set, in to zones.
 Zone groups characters together so as to make the coding scheme
to decipher and the data easier to process.
 With in each zone, the individual characters are identified by
digit code.
 EBCDIC: Pronounced as “Eb-see-dick” and stands for Extended
Binary Coded Decimal Interchange Code.
 It is an 8-bit coding scheme: (00000000 – 11111111), i.e. it uses
8 bits (zone-4 Bits and digit-4 Bits) to represent each character.
 It accommodates to code 28 or 256 different characters.
BCD (Binary Coded Decimal)
 There were two types of BCD coding techniques used before.
 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-bits)
 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 characters
and some other special characters).
ASCII-7
 ASCII stands for American Standard Code for Information
Interchange.
 It uses 7 bits to represent a character.
 With the seven bits, 27( or 128) different characters can be coded
(0000000-1111111).
 It has 3 zone and 4 digit bits positions
The ASCII System
 Also referred as ASCII-8 or Extended ASCII.
 It is commonly used in the transmission of data through data
communication and is used almost exclusively to represent data
internally in microcomputers.
 ASCII uses 8-bits to represent alphanumeric characters (letters,
digits and special symbols).
 With the 8-bits, ASCII can represent 28 or 256 different
characters (00000000-11111111).
 It assigns 4 bits for the zone and the rest for the digit.
Unicode
 Unicode has started to replace ASCII and other coding methods
at all levels.
 It enables users to handle not only practically any script and
language used on this planet;
 it also supports a comprehensive set of mathematical and
technical symbols to simplify scientific information exchange.
 Unicode was originally designed to be a 16-bit code, but it was
extended so that currently code positions are expressed as
integers in the hexadecimal range 0..10FFFF (decimal
0..1 114 111).
Representation of negative
numbers and arithmetic
I. Sign- magnitude representation.
 the left-most bit is used to indicate the sign of the number.
 0 is used to denote a positive number and 1 is used to denote a
negative number.
 But the magnitude part will be the same for the negative and
positive values.
 For example, 11111111 represents-127 while, 01111111
represents + 127.
 We can now represent positive and negative numbers, but we
have reduced the maximum magnitude of these numbers to 127.
 Example 1: Represent-12 using 5-bits sign magnitude
representation
first we convert 12 to binary i. e 1100
Now -12 = 11100
 Example 2: Represent –24 using 8-bits sign magnitude
representation
24=00011000
-24 = 10011000
 In general for n-bit sign magnitude representation the range of
values that can be represented are –(2 n-1-1 ) to (2 n-1-1).
Note: In sign magnitude representation zero can be represented as 0
or -0
II. One’s (1’s) Complement
 all positive integers are represented in their correct binary format.
 For example +3 is represented as usual by 00000011 using 8-bits.

 However, its complement, -3, is obtained by complementing


every bit in the original representation.
 Each 0 is transformed into a 1 and each 1 into a 0.
 In our example, the one’s complement representation of -3 is
11111100.
 Example: +2 is 00000010 using 8-bits
-2 is 11111101
III. Two’s (2’s) Complement
Representation
 positive numbers are represented, as usual, in singed binary, just
like in one’s complement.
 A negative number represented in two’s complement is obtained
by first computing the one’s complement and then add one.
 Example: +3 is represented in signed binary as 00000011
Its one’s complement representation is 11111100.
The two’s complement is obtained by adding one.
It is 11111101.
Fixed format representation
 we have not yet resolved the problem of magnitude.
 If we want to represent large integers, we will need several bytes.

 In order to perform arithmetic operations efficiently, it is


necessary to use a fixed number of bytes, rather than a variable
number.
 Therefore, once the number of bytes is chosen, the maximum
magnitude of the number that can be represented is fixed.
Subtraction with Complements
 The subtraction of two n-digit unsigned numbers M – N in base r can be
done as follows:
Subtraction with Complements
 Example 1.7
 Given the two binary numbers X = 1010100 and Y = 1000011, perform the
subtraction (a) X – Y ; and (b) Y  X, by using 2's complement.

There is no end carry.


Therefore, the answer is Y
– X =  (2's complement of
1101111) =  0010001.
Subtraction with Complements
 Subtraction of unsigned numbers can also be done by means of the 1's
complement. Remember that the 1's complement is one less than the 2's
complement.
 Example 1.8
 Repeat Example 1.7, but this time using 1's complement.

There is no end carry,


Therefore, the answer is Y –
X =  (1's complement of
1101110) =  0010001.
Overflow will occur in four
situations
1. The addition of large positive numbers.
2. The addition of large negative numbers.
3. The subtraction of a large positive number from a large negative
numbers.
4. The subtraction of a large negative number from a large positive
number.
 Overflow indicates that the result of an addition or subtraction
requires more bits than are available in the standard 8-bit
register used to contain the result.
Floating-point representation
 decimal numbers are represented with a fixed length format.
 In order not to waste bits, the representation will normalize all
the numbers.
 For example, 0.000123 wastes three zeroes on the left before non
-zero digits.
 These zeroes have no meaning except to indicate the position of
the Decimal point.
 Normalizing this number result in .123x10-3 .
123 is the normalized mantissa;
-3 is the exponent.
 Example: 111.01 is normalized as .11101x23.
The mantissa is 11101. The exponent is 3.
 The general structure of floating point is

 In representing a number in floating point we use 1 bit for sign,


some bits for exponent and the remaining bit for mantissa.
 In floating point representation the exponent is represented by a
biased exponent (Characteristics).
 Biased exponent = true exponent + excess 2n-1, where n is the
number of bits reserved for the exponent.
 Example: Represent –234.375 in floating point using 7 bit for
exponent and 16 bit for mantissa.
First we have to change to normalized binary,i. e, 234 = 11101010
0.375= 0.011
234.375 = 11101010.011 = 0.11100010011x28
true exponent = 8
excess 2 n-1 = 2 7-1= 26= 64
Biased exponent = 8+26 =8+64 = 72 = (100 1000) 2
Therefore –234.375 is represented as

You might also like