You are on page 1of 10

Chapter 2 : Data Representation.

Arithmetic & Logic Unit Does the calculations Everything else in the computer is there to service this unit Handles integers May handle floating point (real) numbers

Data types represented in binary-coded form Only have 0 & 1 to represent everything can be classified to these categories:

1. Numbers used in arithmetic computation 2. Letters of the alphabet used in data processing 3. Other discrete symbols used for specific purpose Alphanumeric Representation. An alphanumeric character set is a set of elements that includes the 10 decimal digits, the 26 letters of the alphabet and a number of special character such as $, +, and =. 1) The standard alphanumeric binary code: ASCII (American Standard Code for Information Interchange) uses seven bits to code 128 characters. codes must be in binary because registers can only hold binary information.

2) Another alphanumeric code used in IBM equipment; EBCDIC (Extended BCD Interchange Code) that uses 8 bits for each character. BCD (Binary Coded Decimal) represents each individual digit of a decimal number as a group of binary bits; the other formats would convert an entire decimal value to its equivalent binary value. *In the 8421 Binary Coded Decimal (BCD) representation each decimal digit is converted to its 4-bit pure binary equivalent.

8421 BCD Code 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001

Decimal Number 0 1 2 3 4 5 6 7 8 9

Number bases.

The Decimal Number Systems. The Base 10 number system uses the digits: 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9. The Decimal Number System (denary representation) uses base 10. It includes the digits from 0 through 9. The weighted values for each position are as follows:

Power of 10 Value

106 1000000

105 100000

104 10000

103 1000

102 100

101 10

100 1

For example the number 83 means eight tens plus three:

83 = (8 * 10) + 3 The number 4728 means four thousands, seven hundreds, two ten, plus eight:

4728 = (4 * 1000) + (7 * 100) + (2 * 10) + 8 The decimal system is said to have a base, or radix, of 10. This means that each digit in the number is multiplied by 10 raised to a power corresponding to that digits position:

83 = (8 * 101) + (3 * 100) 4728 = (4 * 103) + (7 * 102) + (2 * 101) + (8 * 100) Decimal Fractions The same principle holds for decimal fractions, but negative powers of 10 are used. Thus, the decimal fraction 0.256 stands for 2 tenths plus 5 hundredths plus 6 thousandths: 0.256 = (2 * 10-1) + (5 * 10-2) + (6 * 10-3) A number with both an integer and fractional part has digits raised to both positive and negative powers of 10: 442.256 Most significant digit The leftmost digit (carries the highest value) Least significant digit The rightmost digit Decimal to Binary Conversion Decimal notation to binary notation: Integer and fractional parts are handled separately. Base 10 to 2. To translate 19.687510 to the binary representation, the procedure is to separately consider the digits to the left of the decimal point and those to the right of the decimal point. Let us first consider the number 19. Divide the binary number by 2 and consider the remainder which is either 0 or 1. (4 * 102) + (4 + 101) + (2 * 100) + (2 * 10) + (5 * 10-2) + (6 * 10-3)

19.687510 19/2=9, remainder 1 least significant digit, 9/2 = 4, remainder 1 4/2 = 2, remainder 0 2/2 = 1, remainder 0 1/2 = 0, remainder 1 most significant digit End of operation.

The final number is therefore 10011 0.6875 2 = 1.3750 1 (most significant digit after decimal point) 0.3750 2 = 0.7500 0 0.7500 2 = 1.5000 1 0.5000 2 = 1.0000 1 19.687510 = 10011.10112 Converting to/from Hexadecimal Converting Decimal to Hexadecimal 26 16 = 1 with A left over 1 16 = 0 with 1 left over 2610 = 1A16.

The Binary Number Systems 0, 1 The most basic unit of information that a computer stores is a bit, a variable whose value may be either 0 or 1. Bits are organized into groups of 8 called bytes. The most common unit of computer number information is the 4 byte (32 bit) word. For higher accuracy this is doubled to 8 bytes or 64 bits. There are 2 possible values for a bit, there are 28 =256 possible values for a byte, and there are 232 different 4 byte words, about 4.3 billion. The Binary System Only two digits, 1 and 0 Represented to the base 2 The digits 1 and 0 in binary notation have the same meaning as in decimal notation: 02 = 010 12 = 110 To represent larger numbers each digit in a binary number has a value depending on its position: 102 = (1 * 21) + (0 * 20) = 210 112 = (1 * 21) + (1 * 20) = 310 1002 = (1 * 22) + (0 * 21) + (0 * 20) = 410 and so on. Again, fractional values are represented with negative powers of the radix: 1001.101 = 23 + 20 + 2-1 + 2-3 = 9.62510 The Octal Number System base-8 number system In octal numerals each place is a power with base 8 uses the digits 0,1,2,3,4,5,6,7.

Octal Number to/from Decimal Number. Example 1 : Octal to Decimal 1228 = (1 x 82) + (2 x 81) + (2 x 80) = (1 x 64) + (2 x 8 ) + (2 x 1)

= 64 + 16 + 2 = 8210 Example 2 : Decimal to Octal (102810)

Answer : 20048 Octal Number to/from Binary Number The binary numbers should be grouped into 3 numbers each as 23 = 8. Example binary to octal notation Given : 1111101.10012 001 = 1 111 7 101 5 . . 100 1002 4 4

Answer : 175.448 Example octal to binary notation Given : 56.38 5 = 6 . 3

101 110

. 011

Answer : 101110.0112

The Hexadecimal Number System The hexadecimal number system uses the following digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F. Programmer enters the address using the hexadecimal address of the memory location. The computers operating system translates the hexadecimal number into the binary digits that it understands and retrieves the data.

Much easier for a programmer to tell the computer to go to address 46 than it is 0000 0000 0100 0110.

Hexadecimal Notation Binary digits are grouped into sets of four bits, called a nibble. Each possible combination of four binary digits is given a symbol, as follows: 0000 = 0 0100 = 4 1000 = 8 1100 = C 0001 = 1 0101 = 5 1001 = 9 1101 = D 0010 = 2 0110 = 6 1010 = A 1110 = E 11 0111 = 7 1011 = B 1111 = F Because 16 symbols are used, the notation is called hexadecimal and the 16 symbols are the hexadecimal digits Thus, 2C16 = (216 * 161) + (C16 * 160) = (210 * 161) + (1210 * 160) = 44

Converting to/from Hexadecimal Converting Hexadecimal to Decimal. 1A16 = 1 161 + A 160 = 16 + 10 = 26 Converting Hexadecimal to Binary replace each digit in base 16 by its binary representation in a 4 bit window: (B37.A84)16 to base 2. (B37.A84)16 = (1011 0011 0111 . 1010 1000 0100)2 Same principle applies when converting to and from base 8.

Binary Representations Binary numbers can be stored in 2 different formats: Unsigned numbers Signed numbers (signed magnitude, ones complement, twos complement)

Range for a word length of n bits : 0 (2n 1)

Sign-magnitude representation Assign the leftmost (most significant) bit to be the sign bit. If the sign bit is 0: positive. If the sign bit is 1: negative. Eg, +18 = 00010010 -18 = 10010010

The remaining bits are used to represent the magnitude of the binary number in the unsigned binary notation. Two representations of zero (+0 and -0) cause complications for computers checking numbers for equality. Need to consider both sign and magnitude in arithmetic Disadvantage: performing addition or subtraction we require a special consideration of both signs of the numbers to properly compute the operation. Because of these drawbacks, sign magnitude is rarely used for representing integers Range for a word length of n bits : -(2n-1 1) (2n-1 1)

Twos complement Decimal -> 2s complement If A is positive, represent it using the sign-magnitude representation. The leftmost bit must be 0, and the remaining bits are the binary for the integer. Be careful there are enough bits available to represent the number. If A is negative, first represent in binary +A. - Flip all the 1s to 0s and the 0s to 1s - Add 1 to the result using unsigned binary notation.

1. If the leftmost bit is 0, the number is positive. Compute the magnitude as an unsigned binary number. 2. If the leftmost bit is 1, the number is negative. a. Flip all the 1s to 0s and the 0s to 1s b. Add 1 to the result using unsigned binary notation c. Compute the value as if it were an unsigned binary value, say it is B. magnitude of the negative number. d. The actual value is B. What is the decimal value of the twos complement binary value 11100? Leftmost 1=-ve, Complement / flip=00011 Add 1=00100 Compute the value=4 Ans =-4 This is the

Twos complement benefit - One representation of zero - Arithmetic works easily - Negating is fairly easy E.g. 3 = 00000011 Boolean complement gives Add 1 to LSB 11111100 11111101 Range for a word length of n bits : -(2n-1) (2n-1 1)

You might also like