Presentation is loading. Please wait.

Presentation is loading. Please wait.

Number Systems.

Similar presentations


Presentation on theme: "Number Systems."— Presentation transcript:

1 Number Systems

2 Decimal, Binary, Octal and Hexadecimal Numbers
Most numbering system use positional notation : N = anrn + an-1rn-1 + … + a1r1 + a0r0 Where: N: an integer with n+1 digits r: base ai  {0, 1, 2, … , r-1}

3 N = anrn + an-1rn-1 + … + a1r1 + a0r0
Examples: a) N = 278 r = 10 (base 10) => decimal numbers symbol: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 (10 different symbols) N = 278 => n = 2; a2 = 2; a1 = 7; a0 = 8 278 = (2 x 102) + (7 x 101) + (8 x 100) N = anrn + an-1rn-1 + … + a1r1 + a0r0

4 N = anrn + an-1rn-1 + … + a1r1 + a0r0
b) N = 10012 r = 2 (base-2) => binary numbers symbol: 0, 1 (2 different symbols) N = => n = 3; a3 = 1; a2 = 0; a1 = 0; a0 = 1 10012 = (1 x 23)+(0 x 22)+(0 x 21)+(1 x 20) c) N = 2638 r = 8 (base-8) => Octal numbers symbol : 0, 1, 2, 3, 4, 5, 6, 7, (8 different symbols) N = 2638 => n = 2; a2 = 2; a1 = 6; a0 = 3 2638 = (2 x 82) + (6 x 81) + (3 x 80)

5 d) N = r = 16 (base-16) => Hexadecimal numbers symbol : 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F (16 different symbols) N = => n = 2; a2 = 2; a1 = 6; a0 = = (2 x 162)+(6 x 161)+(3 x 160)

6 Decimal Binary Octal Hexadecimal 1 2 10 3 11 4 100 5 101 6 110 7 111 8 1000 9 1001 1010 12 A 1011 13 B 1100 14 C 1101 15 D 1110 16 E 1111 17 F 10000 20

7 Relation between binary number system and others
Binary and Decimal Converting a decimal number into binary (decimal  binary) Divide the decimal number by 2 and take its remainder The process is repeated until it produces the result of 0 The binary number is obtained by taking the remainder from the bottom to the top

8 Example: Decimal  Binary
Read from the bottom to the top 5310 => 53 / 2 = 26 remainder 1 26 / 2 = 13 remainder 0 13 / 2 = 6 remainder 1 6 / 2 = 3 remainder 0 3 / 2 = 1 remainder 1 1 / 2 = 0 remainder 1 = (6 bits) = (8 bits) (note: bit = binary digit)

9  binary??? => 0.81 x 2 = x 2 = x 2 = x 2 = x 2 = x 2 = 1.84 = (approximately)

10 Converting a binary number into decimal (binary  decimal)
Multiply each bit in the binary number with the weight (or position) Add up all the results of the multiplication performed The desired decimal number is the total of the multiplication results performed

11 Example: Binary  Decimal
a) (6 bits) (1x25) + (1x24) + (1x23) + (0x22) + (0x21) + (1x20) = = 5710 b) (8 bits) = = = 2610

12 Theorem If base R1 is the integer power of other base, R2, i.e.
Binary and Octal Theorem If base R1 is the integer power of other base, R2, i.e. R1 = R2d e.g., 8 = 23 Every group of d digits in R2 (e.g., 3 digits)is equivalent to 1 digit in the R1 base (Note: This theorem is used to convert binary numbers to octal and hexadecimal or the other way round)

13 From the theorem, assume that
R1 = 8 (base-8) octal R2 = 2 (base-2) binary From the theorem above, R1 = R2d 8 = 23 So, 3 digits in base-2 (binary) is equivalent to 1 digit in base-8 (octal)

14 From the stated theorem, the following is a binary-octal conversion table.
In a computer system, the conversion from binary to octal or otherwise is based on the conversion table above. Binary Octal 000 001 1 010 2 011 3 100 4 101 5 110 6 111 7 3 digits in base-2 (binary) is equivalent to 1 digit in base-8 (octal)

15 Example: Binary  Octal
Convert these binary numbers into octal numbers: (a) (8 bits) (b) (8 bits) Refer to the binary-octal conversion table = 578 Refer to the binary-octal conversion table = 3648 3 6 4 5 7

16 Binary and Hexadecimal
The same method employed in binary-octal conversion is used once again. Assume that:   R1 = 16 (hexadecimal) R2 = 2 (binary) From the theorem: 16 = 24 Hence, 4 digits in a binary number is equivalent to 1 digit in the hexadecimal number system (and otherwise) The following is the binary-hexadecimal conversion table

17 Convert the following binary numbers into hexadecimal numbers:
0000 0001 1 0010 2 0011 3 0100 4 0101 5 0110 6 0111 7 1000 8 1001 9 1010 A 1011 B 1100 C 1101 D 1110 E 1111 F Example: Convert the following binary numbers into hexadecimal numbers: (a)   Refer to the binary-hexadecimal conversion table above = 2F16 F

18 Example: Octal  Hexadecimal
Convert the following octal numbers into hexadecimal numbers (16 bits) (a) 658 (b) 1238 Refer to the binary-octal conversion table   = 5316 Refer to the binary-octal conversion table   = 3516 octal  binary  hexadecimal

19 Example: Hexadecimal  Binary
Convert the following hexadecimal numbers into binary numbers (a) 12B16 (b) ABCD16 Refer to the binary-hexadecimal conversion table A B C D16 = Refer to the binary-hexadecimal conversion table B16 (12 bits) =

20 Representation of integer, character and floating point numbers in binary
Introduction Machine instructions operate on data. The most important general categories of data are: 1. Addresses – unsigned integer 2. Numbers – integer or fixed point, floating point numbers and decimal (eg, BCD (Binary Coded Decimal)) 3. Characters – IRA (International Reference Alphabet), EBCDIC (Extended Binary Coded Decimal Interchange Code), ASCII (American Standard Code for Information Interchange) 4. Logical Data - Those commonly used by computer users/programmers: signed integer, floating point numbers and characters

21 Integer Representation -1101.01012 = -13.312510
Computer storage & processing  do not have benefit of minus signs (-) and periods. Need to represent the integer 

22 Signed Integer Representation
Signed integers are usually used by programmers Unsigned integers are used for addressing purposes in the computer (especially for assembly language programmers) Three representations of signed integers: 1. Sign-and-Magnitude 2. Ones Complement 3. Twos Complement

23 Sign-and-Magnitude The easiest representation
The leftmost bit in the binary number represents the sign of the number. 0 if positive and 1 if negative The balance bits represent the magnitude of the number.

24 Examples: i) 8 bits binary number __ __ __ __ __ __ __ __ 7 bits for magnitude (value) a) +7 = (–7 = ) b) –10 = (+10 = ) Sign bit 0 => +ve 1 => –ve

25 5 bits for magnitude (value)
ii) 6 bits binary number   __ __ __ __ __ __ 5 bits for magnitude (value)   a)  +7 = (–7 = ) b)  –10 = (+10 = ) Sign bit 0 => +ve 1 => –ve

26 Ones Complement In the ones complement representation, positive numbers are same as that of sign-and-magnitude Example: +5 = (8 bit)  as in sign-and-magnitude representation Sign-and-magnitude and ones complement use the same representation above for +5 with 8 bits and all positive numbers. For negative numbers, their representation are obtained by changing bit 0 → 1 and 1 → 0 from their positive numbers

27 Convert –5 into ones complement representation (8 bit) Solution:
Example: Convert –5 into ones complement representation (8 bit) Solution: First, obtain +5 representation in 8 bits  Change every bit in the number from 0 to 1 and vice-versa. –510 in ones complement is

28 Exercise: Get the representation of ones complement (6 bit) for the following numbers: i) +710 ii) –1010 Solution: (+7) = Solution: (+10)10 = So, (-10)10 =

29 Twos complement Similar to ones complement, its positive number is same as sign-and-magnitude Representation of its negative number is obtained by adding 1 to the ones complement of the number.

30 Example: Convert –5 into twos complement representation and give the answer in 8 bits. Solution: First, obtain +5 representation in 8 bits  Obtain ones complement for –5 Add 1 to the ones complement number:  = –5 in twos complement is

31 Exercise: Obtain representation of twos complement (6 bit) for the following numbers i) ii)–1010 Solution: (+7) = (same as sign-magnitude) Solution: (+10) 10 = (-10) 10 = = So, twos compliment for –10 is

32 Binary Arithmetics 1. Addition ( + ) = = = = = (1 + 1) + 1 = = 112 Example: i = ii =

33 3. Subtraction ( – ) 0 – 0 = 0 0 – 1 = 1 (borrow 1) 1 – 0 = 1
2. Multiplication ( x ) 0 x 0 = 0 0 x 1 = 0 1 x 0 = 0 1 x 1 = 1 3. Subtraction ( – ) 0 – 0 = 0 0 – 1 = 1 (borrow 1) 1 – 0 = 1 1 – 1 = 0

34 4. Division ( / ) 0 / 1 = 0 1 / 1 = 1


Download ppt "Number Systems."

Similar presentations


Ads by Google