lec 3 number system and data representation

Post on 24-Mar-2015

61 Views

Category:

Documents

3 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Number System and Data Representation

By: H. Cruz

Source: Basic IT Foundation by Albano, et. al

Numbers System (intro) Computer circuits can respond only to binary

numbers. Therefore all data programs must be coded into binary form.

Binary are represented by base 2 number system: either 0 or 1

Decimal System are represented by base 10 number system from 0 to 9

A. Number System Conversion

Decimal Number System or base 10 represented from 0 to 9

Each position is represented by its quantity Ex: 725 - 5 represent the ones place value

2 represented by tens one

7 represented by One hundred values

5 * 100 = 5

2 * 101 = 20

7 * 102 = 700

725

Binary Number System

Binary number system – represented by base 2 number system: either 0 or 1

Each digit in binary notation is associated with quantity except that each position is TWICE as the quantity associated with the position to its right.

The right most represented with the quantity 1

The next position to the left is 2,

The next position is associated with 4;

The next position is association with 16

The next position is associated with 32

Binary number system

Binary to Decimal (conversion)

Representation Position’s quantity

1 1 0 1

One (20 = 1)

Two (21 = 2)

Four (22 = 4)

Eight (24 = 8)

Representation Position’s quantity

1 1 0 1

1* 20 = 1

0 * 21 = 2

1* 22 = 4

1 * 24 = 8

13

Representation Position’s quantity

1 0 0 1

1* 20 = 1

0 * 21 = 0

0* 22 = 0

1 * 24 = 8

9

Convert the ff binary into decimal

1. 101 = 5

2. 11000 = 24

3. 01110 = 14

4. 10100 = 20

5. 110011 = 51

Conversion of Decimal to Binary

1. 8 = 100

Quotient Remainder

8 / 2 4 0

4 / 2 2 0

2 / 2 1 1

Conversion of Decimal to Binary (cont.)

2. 37 = 100101

Quotient Remainder

37 / 2 18 1

18 / 2 9 0

9 / 2 4 1

4 / 2 2 0

2 / 2 1 0

1 / 2 0 1

Convert the ff Decimal into binary number

1. 22

2. 56

3. 87

4. 45

5. 120

Hexadecimal Number System Dump is the process of printing the actual

contents of the memory. The output of dump include strings of binary digits. (very tedious job)

Through hexadecimal notation, a string of bits maybe represented in a shortened for.

The base or radix of hexadecimal number is from 0 to 9, and letters A to F

Hexadecimal notation uses one character or symbol to represents 4 bits.

Hexadecimal to binary

0 0 2 A = One ( 160) 10 x 160 = 10

Sixteen (161) 2 x 161 = 32

Two hundred Fifty six (162) 0 x 162= 0

Four thousand ninety six (163) 0 x 163 = 0

42

Octal number system

A string of 12 bits can be represented by 4 octal systems. Represented from 0 to 7

7 1 5 = One ( 80 = 1 ) 5 x 80 = 5

Eight (81 = 8) 1 x 81 = 8

Sixty Four (82 = 64) 7 x 82 = 448

461

Table of Decimal, Binary, Hexadecimal and Octal

Decimal Binary Hexadecimal Octal 0 0000 0 0 1 0001 1 1 2 0010 2 2 3 0011 3 3 4 0100 4 4 5 0101 5 5 6 0110 6 6 7 0111 7 7 8 1000 8 10 9 1001 9 1110 1010 A 12 11 1011 B 13 12 1100 C 14 13 1101 D 15 14 1110 E 16 15 1111 F 17 16 10000 10 20

B. Number System Operations

1. Decimal base to Binary base – continuous division by 2

Hexadecimal base or Octal Base System.

Study the given examples

1. What is 13 base 10 in _____ base 2? (continuous division by 2)

13 / 2 = 6 1

6 / 2 - 3 0

3 / 2 = 1 1

1 / 2 = 0 1

Answer: 1101

Exer: 129 base 10 is equal to 10000001 base 2

What is 54 base 10 in base 161. What is 54 base 10 in base 16? 36

54 / 16 = 3 6

3 / 16 = 0 3

2. What is 108 base 10 in base 16?

108 / 16 =

2. Binary Notation of Hexadecimal and Octal Notation

Hexadecimal Symbol represents the series of 4 bits, while Octal symbol represents a series of 3 bit

In order to convert binary to decimal, must arrange the binary digits into groups of 4

Starting from the right most, arrange the binary digits into groups of 4

Converts each groups into hexadecimal by multiplying it by its position value and get the sum of each.

Ex: 101010101011012 to _________16

1. 10 1010 1010 1101

2 10(A) 10(A) 13(B) = 2AAB

2. 11 0110 01112 = ____367_______16

11 0110 0111

3 6 7

Binary to Octal conversion

Convert 10101010 (base2) it octal equivalent

1. Arrange the binary digits into groups of 3

10 101 010

2. For each group, convert each digit to hexadecimal by multiplying by its position value

10 101 010

2 5 2

Binary to Octal(3 bit)1. How 17 base 8 represented in base 2

1 111

1 7

2 How 45 base 8 represented in base 2

100 101

4 5

Addition and Subtraction of Binary Numbers

0 0 1 1

+ 0 + 1 + 0 + 10 1 110

Ex: 11 1010 10110

+100 + 1100 + 10111

111 10110 101101

Addition of Hexadecimal

1. What is the result of ABC16 + 2AA16?

Solution: 1 1

ABC16 10 11 12

2AA16 2 10 10

13 22 22

-16 -16

13 6 6

D 6 616

Addition done by adding the given hexadecimal value.

If the added hexadecimal value exceeds the base radix, subtract the radix and get the result.

Add 1 to the next highest value of hexadecimal

Addition of Hexadecimal

1. What is the result of 2DE16 + FED16?

2. What is the result of CADE +

CAFE?

3. What is the result of AE12 + FACADE

4FE16 4 15 14

+ 2ED16 2 14 13

2 1 1

Addition of Octal

1. What is the result of 7528 + 5678?

Solution:

1 1 1

7 5 2

+ 5 6 _ 7

13 12 9

- 8 -8 -8

1 5 4 1

Add the given octal value.

If the added octal values exceeds the base or radix, subtract the radix, and get the results, then, add 1 to the next highest value of octal.

If there are extra decimal value to the next highest position, just bring down the remaining decimal value.

Octal Addition1. What is the result of

51078 + 655678?

Answer:

1

1 5 1 0 7

+ 6 5 5 6 7

7 10 6 7 14

-8 -8

7 2 6 8 6

Binary Subtraction

0 0 1 1- 0 - 1 - 0 + 1

0 0borrow with 1 1 0

1. 1010(10) 2. 10000(16) 3. 100011- 100(4) - 1111(15) - 1111

110(6) 1 10100

Subtraction of Hexadecimal 1. What is the result of 5238 -

3578?

Answer:

5 (4) 2(1+8) =9 (3+8 =11)- 3 5 7

1 4 48

Subtract the given hexadecimal value if the hexadecimal minuend is less than the hexadecimal borrow to the next hexadecimal position. If any results change those decimal digits to its corresponding letters.

C. Fixed – Point Number Representation

A. BCD (Binary Coded Decimal) Format

Is one which the decimal digits are stored in terms of their 4-bit binary equivalents. There are two (2) basic format:

1. Packed Format – the decimal digit is stored in a sequence of 4-bit groups.

The number 2004

0010 0000 0000 0100

2 0 00 4

Packed format (cont.)

In packed format, 1 byte represents a numeric values of 2 digits and the least significant 4 bits represents the sign.

The pattern for zero is 1100 – positive sign The pattern for one is 1101 - negative sign Ex: +689 0110 1000 1001 1100 Ex: -689 0110 1000 1001 1101

2. Unpacked Format also called zoned-decimal format.

Unpacked format, a decimal digit is stored in the low-order part of an 8-bit group and what is put into the high-order part is unimportant.

Format stored as: 2004uuuu0010 uuuu0000 uuuu0000 uuuu0100

2. Unpacked Format also called zoned-decimal format.

The high order part is called zone-bits. In case of the EBCDIC (Extended Binary Coded Decimal Interchange Code) used in high end mainframes, the zone bits would store (1111) base 2. However the high order part of the least significant digit represents the sign. The assigned bits for positive 1100 and negative are 1101; respectively

Ex: +689 1111 0110 1111 1000 1100 1001

zone 6 zone 8 zone 9

bit bit bit

2. Unpacked Format also called zoned-decimal format.

Ex: -689 1111 0110 1111 1000 1101 1001

zone 6 zone 8 zone 9

bit bit bit

B. Positive IntegerDecimal number are usually converted first to the

binary equivalent. If we have an 8 bit register, it may express integer decimal numbers between 0 and 28 -1 or 255.

If we have a bit of 16 bit register, we can store integer decimal numbers between 0 and 216 -1 or 65536.

The magnitude of the number that can be stored in a register is 28 -1 where n is the number of bits with the register of memory cell.

C. Negative number There are two (2) ways of representing negative

number:

1. Absolute value representation – negative numbers can be represented by attaching an extra bit to indicate the sign bit (leftmost).

The resulting format is called sign-magnitude format

Ex: +16 = 0001 0000 (sign bit is 0 to indicate the plus sign)

-16 = 1001 0000 (sign bit is 0 to indicate the plus sign)

(This format representing negative numbers is seldom use)

C. Negative number (cont.)

2. The complement representation of a number is the amount of necessary to add to a number to make it complete for a given number of system.

Thus is binary= 0 is complement of 11 is complement of 0

The one’s complement representation is where the bit is complemented:

Ex: the one’s complement of: 10011 is 01100

C. Negative number (cont.) The two’s complement is obtained by adding one

to the one’s complement. 01001 10110

+1

____________

10111

Determine the One’s complement of the ff:

1. 1101110012

2. 0011011102

3. 11010101012

4. 1010110

5. 1111110

Determine the Two’s complement of the ff:

1. 1101110111101

2. 01011101

3. 4510

4. 23410

top related