Number Systems

43
NUMBER SYSTEMS

Transcript of Number Systems

Page 1: Number Systems

NUMBER SYSTEMS

Page 2: Number Systems

DECIMAL (BASE 10) NUMBER SYSTEM

Decimal system is the most commonly used number system. Our present system of numbers has 10 separate symbols namely 0,1,2,3,4,5,6,7,8 and 9, which are called Arabic numerals.

The base or radix of a number system is defined as the number of different digits, which can occur in each position in the number system. The decimal system has a base or radix of 10.

Page 3: Number Systems

In a positional number system, the position a symbol occupies in the number determines the value it represents.

The following shows the place values for the integer +224 in the decimal system.

Note that the digit 2 in position 1 has the value 20, but the same digit in position 2 has the value 200. Also note that we normally drop the plus sign, but it is implicit.

Page 4: Number Systems

The following shows the place values for the decimal number −7508. We have used 1, 10, 100, and 1000 instead of powers of 10.

( ) Values

The following shows the place values for the real number +24.13

Page 5: Number Systems

Place values for an integer in the decimal system

Page 6: Number Systems

BINARY (BASE 2) NUMBER SYSTEMThe word binary is derived from

the Latin root bini (or two by two). In this system the base b = 2 and we use only two symbols,

The symbols in this system are often referred to as binary digits or bits (binary digit).

S = {0, 1}

Page 7: Number Systems

OCTAL (BASE 8) NUMBER SYSTEMThe word octal is derived from

the Latin root octo (eight). In this system the base b = 8 and we use eight symbols to represent a number. The set of symbols isS = {0, 1, 2, 3, 4, 5,

6, 7}

Page 8: Number Systems

HEXADECIMAL (BASE 16) NUMBER SYSTEM

The word hexadecimal is derived from the Greek root hex (six) and the Latin root decem (ten). In this system the base b = 16 and we use sixteen symbols to represent a number. The set of symbols isS = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F} Note that the symbols A, B, C, D,

E, F are equivalent to 10, 11, 12, 13, 14, and 15 respectively. The symbols in this system are often referred to as hexadecimal digits.

Page 9: Number Systems
Page 10: Number Systems

NUMBER CONVERSIONS :- DECIMAL TO BINARY

Consider the integer and fractional parts separately.

For the integer part,◦Repeatedly divide the given number by

2, and go on accumulating the remainders, until the number becomes zero.

◦Arrange the remainders in reverse order.

For the fractional part,◦Repeatedly multiply the given fraction

by 2. Accumulate the integer part (0 or 1). If the integer part is 1, chop it off.

◦Arrange the integer parts in the order they are obtained.

Page 11: Number Systems

DECIMAL –TO – BINARY CONVERSION

Page 12: Number Systems

Convert 9310 to binary93 / 2 = 46 remainder 1 (least significant digit)46 / 2 = 23 remainder 023 / 2 = 11 remainder 111 / 2 = 5 remainder 15 / 2 = 2 remainder 12 / 2 = 1 remainder 01 / 2 = 0 remainder 1 (most significant digit)

Ans:- 1011101

Page 13: Number Systems

BINARY – TO – DECIMAL CONVERSION The easiest method for converting

a binary number to its decimal equivalent is to use the Multiplication Algorithm

The following shows how to convert the binary number (110.11)2 to decimal: (110.11)2 = 6.75.

Page 14: Number Systems
Page 15: Number Systems

DECIMAL – TO – OCTALThe following shows how to

convert 126 in decimal to its equivalent in the octal system. We move to the right while continuously finding the quotients and the remainder of division by 8. The result is 126 = (176)8.

Page 16: Number Systems

Conversion of decimal fraction to octal fraction is carried out in the same manner as decimal to binary except that now the multiplication is carried out by 8.Find the octal equivalent of (0.75)10. Number (to be recorded)0.75 × 8 = 6.00 6 0 x 8 = 0 0(0.75)10=(0.6)8

Page 17: Number Systems

2.17

The following shows how to convert (23.17)8 to decimal.

This means that (23.17)8 ≈ 19.234 in decimal. Again, we have rounded up 7 × 8−2 = 0.109375.

OCTAL – TO – DECIMAL

Page 18: Number Systems

2.18

The following shows how we convert 126 in decimal to its equivalent in the hexadecimal system. We move to the right while continuously finding the quotients and the remainder of division by 16. The result is 126 = (7E)16

DECIMAL – TO – HEX

Find the hexadecimal equivalent of (0.75)10. Number (to be recorded)0.75 × 16 = 12.00 C (12 = C)Thus (0.75)10= (0.C)16.

Page 19: Number Systems

2.19

The following shows how to convert the hexadecimal number (1A.23)16 to decimal.

Note that the result in the decimal notation is not exact, because 3 × 16−2 = 0.01171875. We have rounded this value to three digits (0.012).

HEX –TO – DECIMAL

Page 20: Number Systems

2.20

An alternative method for converting a small decimal integer (usually less than 256) to binary is to break the number as the sum of numbers that are equivalent to the binary place values shown:

Page 21: Number Systems

21

ExampleExample: convert decimal 106 to binary

◦ Step 1: You need 7 bits (see earlier slides for explination).

◦ Step 2: keep track of position values for bits64 32 16 8 4 2 1--------------------------------------------------------------------------------? ? ? ? ? ? ?◦ Step 3: Check leftmost position value (i.e. 64)

64 is less than 105, therefore the first binary digit is 1

64 32 16 8 4 2 1--------------------------------------------------------------------------------1 ? ? ? ? ? ?

subtract : 106 - 64 = 42

Page 22: Number Systems

22

Example (continued-2)◦ Step 4: Check next position value (i.e. 32)

32 is less than 42, therefore the next binary digit is 1

64 32 16 8 4 2 1-------------------------------------------------------------------------------1 1 ? ? ? ? ?

subtract : 42 - 32 = 10

◦ Step 4(continued): Check next position value (i.e. 16) 16 is greater than 10, therefore the next binary digit is 0

64 32 16 8 4 2 1-------------------------------------------------------------------------------1 1 0 ? ? ? ?

Page 23: Number Systems

23

Example (continued-3)◦ Step 4(continued): Check next position value (i.e. 8)

8 is less than 10, therefore the next binary digit is 1

64 32 16 8 4 2 1-------------------------------------------------------------------------------1 1 0 1 ? ? ?

subtract : 10 - 8 = 2

◦ Step 4(continued): Check next position value (i.e. 4) 4 is greater than 2, therefore the next binary digit is 0

64 32 16 8 4 2 1-------------------------------------------------------------------------------1 1 0 1 0 ? ?

Page 24: Number Systems

24

Example (continued-4)◦ Step 4(continued): Check next position value (i.e. 2)

2 is equal to 2, therefore the next binary digit is 1

64 32 16 8 4 2 1------------------------------------------------------------------------------- 1 10 1 0 1 ?

Since the position value was equal to the number (i.e. 2) the rest of the binary digits are all zeros

64 32 16 8 4 2 1---------------------------------------------------------------------------1 1 0 1 0 1 0

◦ Answer: 1101010

Page 25: Number Systems

Octal to Binary ConversionEach octal number converts to 3 binary

digitsTo convert 6538 to binary, just substitute code:

6 5 3

110 101 011

Show the octal equivalent of the binary number (101110010)2101 110 010The result is (562)8.

Page 26: Number Systems

Binary to Hexadecimal ConversionThe easiest method for converting

binary to hexadecimal is to use a substitution code

Each hex number converts to 4 binary digits

Page 27: Number Systems

Show the hexadecimal equivalent of the binary number (10011100010)2.

SolutionWe first arrange the binary number in 4-bit patterns: 0100 1110

0010hexadecimal: (4E2)16.

What is the binary equivalent of (24C)16SolutionEach hexadecimal digit is converted to 4-bit patterns:2 → 0010, 4 → 0100, and C → 1100The result is (001001001100)2.

Page 28: Number Systems

2.28

Octal-hexadecimal conversion

Octal to hexadecimal and hexadecimal to octal conversion

Page 29: Number Systems

BINARY REPRESENTATION OF INTEGERS

Page 30: Number Systems

Range of unsigned integers # of Bits

---------8

16

Range-------------------------------------0 2550 65,535 0 to 2 (n) -1Ex:- Store 7 in an 8-bit memory location

First change the number to binary 111. Add five 0s to make a total of N (8) bits, 00000111. The number is stored in the memory location.

Page 31: Number Systems

Example of storing unsigned integers in two different computers

Decimal-----------

-7

234258

24,7601,245,6

78

8-bit allocation------------

0000011111101010overflowoverflowoverflow

16-bit allocation---------------------------

---000000000000011

1000000001110101

0000000010000001

0011000001011100

0overflow

Page 32: Number Systems

Range of signed integers

# of Bits

----------81632

-127 -0-32767 -0-2,147,483,647 -0

+0 +127 +0 +32767 +0 +2,147,483,647

Range------------------------------------------------

-------

Page 33: Number Systems

SIGN AND MAGNITUTDE In sign-and-magnitude representation,

the leftmost bit defines the sign of the number. If it is 0, the number is positive. If it is 1, the number is negative.

Eg:- Store +7 in an 8-bit memory location using sign-and-magnitude representation.

First change the number to binary 111. Add four 0s to make a total of N-1 (7) bits, 0000111. Add an extra zero because the number is positive. The result is: 00000111

Page 34: Number Systems

Note

There are two 0s in sign-and-magnitude representation: positive and negative.In an 8-bit allocation:+0 00000000-0 10000000

Store –258 in a 16-bit memory location using sign-and-magnitude representation

First change the number to binary 100000010. Add six 0s to make a total of N-1 (15) bits, 000000100000010. Add an extra 1 because the number is negative. The result is: 1000000100000010

Page 35: Number Systems

Interpret 10111011 in decimal if the number was stored as a sign-and-magnitude integer.

Ignoring the leftmost bit, the remaining bits are 0111011. This number in decimal is 59. The leftmost bit is 1, so the number is –59.

Page 36: Number Systems

ONE’S COMPLEMENT If the sign is positive (0), no more

action is needed;If the sign is negative, every bit is

complemented.(i.e. just replace every 0 with 1 and every 1 with 0 )

In one’s complement representation, the leftmost bit defines the sign of the number. If it is 0, the number is positive. If it is 1, the number is negative (Here also 0 has two representation)

Page 37: Number Systems

Store +7 in an 8-bit memory location using one’s complement representation.◦First change the number to binary 111. Add

five 0s to make a total of N (8) bits, 00000111. The sign is positive, so no more action is needed. The result is: 00000111

Store –258 in a 16-bit memory location using one’s complement representation◦ First change the number to binary 100000010. Add

seven 0s to make a total of N (16) bits, 0000000100000010. The sign is negative, so each bit is complemented. The result is:

1111111011111101

Page 38: Number Systems

Interpret 11110110 in decimal if the number was stored as a one’s complement integer. The leftmost bit is 1, so the number is negative. First complement it . The result is 00001001. The complement in decimal is 9. So the original number was –9. Note that complement of a complement is the original number.

One’s complement means reversing all bits. If you one’s complement a positive number, you get the corresponding negative number. If you one’s complement a negative number, you get the corresponding positive number. If you one’s complement a number twice, you get the original number.

Page 39: Number Systems

TWO’S COMPLEMENT Two’s complement is the most

common, the most important, and the most widely used representation of integers today.

If the sign is positive, no further action is needed;

If the sign is negative, find 2’s complement of a number by adding 1 to its 1’s complement.

In 2’s Complement there is one unique 0. (i.e. The two’s complement of 0 is 0)

Page 40: Number Systems

TWO’S COMPLEMENT To convert from decimal to two's

complement: ◦ If number is positive, convert number from

decimal to binary ◦ If number is negative:

Convert absolute value of number from decimal to binary

Complement the bits Add 1

In two’s complement representation, the leftmost bit defines the sign of the number. If it is 0, the number is positive.If it is 1, the number is negative.

Page 41: Number Systems

Store +7 in an 8-bit memory location using two’s complement representation.◦First change the number to binary 111. Add

five 0s to make a total of N (8) bits, 00000111. The sign is positive, so no more action is needed. The result is: 00000111

Store –258 in a 16-bit memory location using two’s complement representation◦ First change the number to binary 100000010. Add

seven 0s to make a total of N (16) bits, 0000000100000010. The sign is negative, so each bit is complemented. : 1111111011111101 add 1 to get 2’s complement :

◦ 1111111011111110

Page 42: Number Systems

REPRESENTING CHARCTERS IN MEMORY ASCII CODE:-

◦ Acronym for the American Standard Code for Information Interchange. Pronounced ask-ee,

◦ It is the most common format for text files in computers and on the Internet. In an ASCII file, each alphabetic, numeric, or special character is represented with a 7-bit binary number (a string of seven 0s or 1s). 128 possible characters are defined (0-127).

◦ There are 128 values ranging from 0 to 127, of which 95 are printable characters and 33 are not visible but used for control characters. Carriage return (0xD16 in hexadecimal) and linefeed (0xA16 ) are two of the better known control characters.

Page 43: Number Systems

ISCII CodeIndian Standard Code for Information

Interchange. This is 8-bit code capable of encoding 256 characters. ISCII retains all ASCII characters and offers coding for Indian scripts also. Thus, also called as Indian Scripts for Information Interchange.

UNICODE◦ A 16-bit character set standard, designed

and maintained by the non-profit consortium Unicode Inc.

◦ Unicode was designed to be universal, unique, and uniform, i.e., the code was to cover all major modern written languages (universal), each character was to have exactly one encoding (unique), and each character was to be represented by a fixed width in bits (uniform).