Numbering systems The decimal numbering system is widely used, because the people Accustomed (معتاد) to use the hand fingers in their counting. But with the development of the computer science another numbering systems are founded. Such as: Binary, Octal, Hexadecimal, or any base r > 2. Numbering systems classification Positional numbering systems: that depends on the position of the digit in the number. Which means that the same digit can take different values according to his position [decimal, Binary, Octal, Hexadecimal] None positional numbering systems: that don t use digit weights in the numbers. [ROMAN numbering system] 1
Numbering Systems Radix The base or the radix of any numbering system is equal to the number of symbols that used to represent its numbers The decimal number system is said to be of Base (Radix), 10 because it uses 10 digits [ 0,1,2,.,9] The Binary number system is said to be of Base (Radix), 2 because it uses 2 digits [ 1,0 ] The Octal number system is said to be of Base (Radix), 8 because it uses 8 digits [0,1,2,3.,7] The Hexadecimal number system is said to be of Base (Radix), 16 because it uses 16 digits [0,1,2,3..,A,B,C,D,E,F] 2
decimal numbers The decimal number representation X= (d j d j-1.d 3 d 2 d 1 d 0.d -1 d -2 d -3, d -(k-1) d -k ) 10, where dj (digit): 0,1,2.9, j ( position): 3,2,1,0,-1,-2,-3.. X as a decimal number with j digits can be represented as X=10 j *d j +10 j-1 *d j-1.+10 2 *d 2 +10 1 *d 1 +10 0 *d 0 +10-1 *d -1 +10-2 *d -2 +.10 -(k-1) *d -(k-1) +10 -k *d -k the integer part of the number is represented by an ascending positive power The fraction part of the number is represented by an ascending negative power 3
4
Positional representation rule for numbers All positional numbering systems are the same in that they are depends on the wait of the digits in the number, and different only in the base. So we can use the same method of representing decimal numbers to be accepted by any other numbering system. As follows: N= i=n i= m a i R i Where : R- base of the system, ai- the digits of the number, m- the number of the fraction digits part, n- number of the integer part digits - 1 5
Binary system Is of base 2 and has two digits (0,1) It is the system that used by the computer It is represented in the electronic circuits as two states: on 1 off 0 6
Binary Digits (Bits) Only 2 states possible On 1 Electronic pulse present Positive magnetic field Off 0 Electronic pulse absent Negative magnetic field } Human readable symbols } Inside the computer s memory (RAM) } Permanently stored on disks On Off Pitted Not Pitted } Permanently stored on CD-ROM 7 Light Pulse No Light Pulse } Fiber Optic Cable
Binary representation Using the previous rule we can represent any binary number as x=.b 2 *2 2 +b 1 *2 1 +b 0 *2 0 +b -1 *2-1 +b -2 *2-2.. Where: b i =0,1 8
Most significant bit least significant bit 9
Octal system The base of this system is 8. Its symbols are (0,1,2.7) Using the previous rule we can represent any octal number as x=.o 2 *8 2 +o 1 *8 1 +o 0 *8 0 +o -1 *8-1 +o -2 *8-2.. Where: o i =0,1,2,3,4,5,6,7 10
11
Hexadecimal system The base of this system is 16 it has 16 digits(0,1,2.9,a,b,c,d,e,f) A=10,B=11,C=12,D=13,E=14,F=15 Using the previous rule we can represent any hexadecimal number as x=.h 2 *16 2 +H 1 *16 1 +H 0 *16 0 +H -1 *16-1 +H -2 *16-2.. Where: H i =0,1,2,3,..9, A,B,C,D,E,F 12
13
Number base conversions Base R to decimal conversion A number expressed in base R can be converted to its decimal equivalent by using the Positional representation rule [ multiplying each coefficient with the corresponding power of R and adding] N= i=n i= m a i R i 14
Binary to decimal Number base conversions 15
Number base conversions Octal To Decimal Conversion Examples: (312.1) 8 =3*8 2 +1*8 1 +2*8 0 +1*8-1 =(3X64)+(8)+(2)+(1/8)=(202.125) 10 (752) 8 =7*8 2 +5*8 1 +2*8 0 =(7X64)+(5X8)+(2X1)=(490) 10 16
Number base conversions Hexadecimal to Decimal Conversion 17
Number base conversions Decimal to base R conversion The conversions from decimal to any base R number system is more convenient if the number is separated into an integer part and a fraction part and the conversion of each part is done separately. Example (d 3 d 2 d 1 d 0.d -1 d -2 d -3 ) 10 ( ) r (d 3 d 2 d 1 d 0 ) 10 ( ) r (.d -1 d -2 d -3 ) 10 ( ) r Integer part divided by base R Fraction part multiplied by base R 18
19 From decimal to binary We use the remainder method as follows: a) Integer part 1. The integer part of the number is divided by 2 2. The reminder calculated 3. The quotient resulted from step 1 divided by 2 4. The reminder calculated 5. The previous steps are repeated until the quotient becomes equal to 0 6. The required binary number is the collection of reminders ordered from the last reminder to the first one
From decimal to binary b) fraction part Converting fraction part is done using the multiplication instead of division as follows: 1. multiply the number by 2 2. Get the integer part from the result obtained from step 1 3. Multiply the fraction obtained in step1 by 2 4. Get the integer part from the result obtained from step 3 5. Repeat the above steps until we have the fraction part of the multiplication equals to 0 or we reached the required precision 6. The required number is the collection of integer digits obtained after each multiplication. 20
Examples ( ) 2 21
Examples Example : Convert the following decimal numbers to Binary numbers 1- (29)10 2-(53)10 3-(41)10 1: Division Remainder 29/2 1 LSB 14/2 0 7/2 1 3/2 1 1/2 1 MSB 0 (29)10 =(11101)2 2: (53)10 Division Remainder 53/2 1 LSB 26/2 0 13/2 1 6 /2 0 3 /2 1 1 /2 1 MSB 0 (53)10 =(110101)2 3 : (41)10 41/2 1 LSB 20/2 0 10/2 0 5 /2 1 2 /2 0 1 /2 1 MSB 0 22 (41)10 =(101001)2
Examples Convert the following decimal number to a binary (0.78125) 10 23
Examples Example: Convert the following decimal number into binary Number 1: (0.828125 )10 0.828125 x2 = 1+ 0.65625 1 MSB 0.65625 x 2 = 1+ 0.3125 1 0.3125 x 2 = 0+ 0.625 0 0.625 x 2 = 1+ 0.25 1 0.25 x 2 = 0+ 0.5 0 0.5 x 2 = 1+ 0 1 LSB (0.828125)10 =(0.110101)2 2: (41. 625 )10 =(41)10 + (0.625 )10 from the above example (41)10 is represented by (101001)2 (0.625 )10 is 0.625 x 2 = 1+ 0.25 1 MSB 0.25 x 2 = 0+ 0.5 0 0.5 x 2 = 1+ 0 1 LSB (0.625 )10 = (101)2 so (41. 625 )10 = (101001.101)2 while 24
Decimal to octal Example: Convert the following decimal number into octal Number (153.6875) 10 (231.54) 10 25
Decimal to hexadecimal Example: Convert the following decimal number into hexadecimal Number (125.34375) 10 26
Binary to octal or hexadecimal and vise versa Each octal digit corresponds to 3 binary digits Base 8 = 2 3 Each hexadecimal digit corresponds to 4 binary digits Base 16=2 4 27
Binary to octal Group each 3 binary digits from the radix point 28
Binary to octal 29
Binary to hexadecimal Group each 4 binary digits from the radix point 30
Binary to hexadecimal 31
Octal or hexadecimal to binary Each octal digit is converted to 3 binary digits according to the table 32
Octal or hexadecimal to binary Each hexadecimal digit is converted to 4 binary digits according to the table 33
Examples 34
Examples 35
Signed Number Representation : Any signed number can be represented using one of the following methods: A) Signed (true) and Magnitude Representation (SAM) B) complements R s complement (R-1) s complement Where R is the base of the system 36
Signed Number Representation : A) Signed (true) and Magnitude Representation (SAM): the leftmost bit (MSB) is used as a sign bit,where 0 indicates a positive integer and R-1 indicates a negative integer. The rest of the number is the magnitude 0 1101011 sign =0 : positive 1101011 = 107 0 1 1 0 1 0 1 1 Sign bit magnitude 1 1101011 sign =1 : Negative 1101011= -107 37
Signed Number Representation : Examples Represent the following numbers using the SAM method, where each number is of 6 digits, one of them for the sign (+ 67) 8 0 00067 (-67) 8 7 00067 (-2E) 16 (+ 4F) 16 F 0002E 0 0004F 38
Signed Number Representation : B) Complements form Complements are used in digital computers for simplifying the subtraction and for logical manipulations There are two types of complements for each base R system: 1. r s complements 2. (r-1) s complements, r >= 2 base number 39
R s complement Given a positive number N in base r with an integer part of m digits, the r s complement of N is defined as r s complement( N)= r m -N, N#0 Example: 0, N=0 the 10 s complement of (25.639) 10 = (10 2 ) 10 - (25.639) 10 = 74.361 the 8 s complement of (732.123) 8 = (8 3 ) 10 - (732.123) 8 = (45.655) 8 The 2 s complement of (10101.0110) 2 =(2 5 ) 10 - (10101.0110) 2 = 100000-10101.0110=(1010.1010) 2 40
(R-1) s complement Given a positive number N in base r with an integer part of m digits, and a fraction part of k digits, the (r-1) s complement of N is defined as (R-1) s complement( N)= r m -r -k -N, no meter if n=0 Examples: The 9 s complement of (25.639) 10 10 2-10 -3-25.639=100-1/1000-25.639=(74.360) 10 The 9 s complement (25) 10 10 2-10 0-25= 74 The 7 s complement of (731.132) 8 (8 3 ) 10 -(8-3 ) 10 -(731.132) 8 =(46.645) 8 The 1 s complement of (1110100) 2 (2 7 ) 10-2 0 - (1110100) 2 =128-1-116=(11) 10 =(0001011) 2 41
Basic rules for binary addition and subtraction 42
1 s Complement Change each 0 to 1 and each 1 to 0 Example: find the 1 s complement of the following binary numbers 0101 the 1 s complement is 1010 01101101010 10010010101 the 1 s complement is 43
2 s complement 2 s complement= 1 s complement +1 Example: find the 2 s complement of the following binary numbers. 1101101 1 s complement 0010010 2 s complement= 1 s complement + 1 = 0010010+1=0010011 01101101010 1 s complement 10010010101 2 s complement= 1 s complement +1= 10010010101 + 1 =1001001010 44
45
Binary Arithmetic Unsigned Numbers 1- Binary Addition: Example: 1111 0100 Carries 0000 0010 Carries 0011 1011 1011 1001 + 0111 1010 + 0100 0101 1011 0101 1111 1110 1111 0000 Carries 1110 0000 0000.0000 Carries 1111 1001 0101 1000 1001.1001 + 0100 1000 + 0011 0011 0100.0100 ---------------- ----------------------------- 1 0100 0000 overflow 1000 1011 1101.1101 46
Unsigned Binary Addition Example 4 bit numbers can represent numbers from 0 to 15 47 The result 18 is not in the range [0,15], And is too big. Consequently, Overflow happens here. So the carry bit from adding the two most significant bits represents a results that overflows.
Binary Subtraction I- Using 2 s complement: 1:- Find the 2's complement for the number with negative sign 2:- Add the 2 s complement to the second number. 3:- if the result is with a last carry (carry =1) then the result is positive discard the last carry, otherwise (carry=0) the result is negative and it is in the 2 s complement form ( get the 2's complement of the result and put a negative sign in front of the number). Example 1: 3 11 11 11-2 -10 01+1 + 10 --- ----- ------- ------- 1 1 01 carry =1 result positive =01 48
Using 2 s complement Example 2: 9 1001 1001 1001-5 -0101 1010+1 + 1011 ------- --------- ----------- ---------- 4 1 0100 carry=1 positive result=0100 Example 3: 4 100 100 100-5 -101 010 +1 + 011 ----- ------- ---------- ------- -1 0 111 carry=0 Negative result (2 s complement form) 111 2 s comp. 000+1-001= -1 49
Using 2 s complement Example 4: 5 0101 0101 0101-9 -1001 0110+1 +0111 ------ --------- ----------- ---------- -4 0 1100 carry=0 negative result (2 s complement form) 1100 2 s comp. 0011+1-100= - 4 50
II- Using 1 s complement II- Using 1 s complement: - Get the 1's complement for the number with the negative sign - add the 1 s complement to the second number - if an end carry occur (carry =1 (end around carry)) add it to the least significant bit and the answer is positive. - otherwise (carry=0) : the answer is negative in the 1 s complement form (get the 1's complement of the result and put a negative sign in front of the number) Example 1: 9 1001 1001 0011-5 -0101 + 1010 + 1 --- ------- -------- --------- 4 1 0011 0100 carry=1 (end around carry) positive result=0100=4 51
Example 2: II- Using 1 s complement 4 100 100-5 - 101 + 011 ----- ------- ------ -1 110 carry=0 negative result in1 s complement form 1 s complement of 110 is 001=-1 52
Signed Binary Addition Example signed 4 bit numbers (2's complement) can represent numbers between -7 to 7 The extra carry from the most significant bit has no meaning 53
Signed Binary Addition Example signed 4 bit numbers (2's complement) can represent numbers between -7 to 7 if two numbers with the same sign (either positive or negative) are added and the result has the opposite sign, an overflow has occurred. 54
Binary Multiplication There are two methods fo multiplication 1. Shift and add 2. Repeated addition 1. shift and add the multiplication in the binary system is the same as the multiplication in the decimal system. by shift and add. 0x0=0 0x1=0 1x0=0 1x1=1 Example: 5 101 x 2 x 10 ----- ------ 10 000 101 -------- 1010 55
Binary Multiplication 2. Binary Multiplication by Repeated Addition Repeated addition - add the second number to itself the number of times represented by the first multiplicand. Set result to 0 Repeat Add second multiplicand to result Reduce first multiplicand by 1 Until first multiplicand = 0 Result is correct STOP 56
Binary Multiplication Example 5 101 101 100 11 10 1 0 x 2 x 10 x 10 x 10 x 10 x 10 x 10 x 10 ---------- -------- ------- -------- ------- ------ ------ ------ 10 0 10 100 110 1000 1010 stop 57
Binary division There are two methods for binary division 1. shift subtract 2.repeated subtraction 1. shift subtract Set quotient to 0 Align leftmost digits in dividend and divisor Repeat If that portion of the dividend above the divisor is greater than or equal to the divisor Then subtract divisor from that portion of the dividend and Concatenate 1 to the right hand end of the quotient Else concatenate 0 to the right hand end of the quotient Shift the divisor one place right Until dividend is less than the divisor quotient is correct, dividend is remainder STOP 58
Binary division. 59
Binary division 2. Binary Division by Repeated Subtraction Set quotient to zero (quotient as counter) Repeat while dividend is greater than or equal to divisor Subtract divisor from dividend Add 1 to quotient End of repeat block quotient is correct, dividend is remainder STOP 60
Binary division 1111/11 61
Binary division 111 /10 62
Binary codes When numbers, letters, or words are represented by a special group of symbols, this is called encoding. And the group of symbols is called a code When a decimal number is represented by its equivalent binary number, we call it binary coding Ex. decimal binary code 0 0 1 1 2 10 3 11... 63
Base 4 code Base 4 : 0, 1, 2, 3 Binary code: 00, 01, 10, 11 decimal base 4 0 0 1 1 2 2 3 3 4 10 5 11 6 12 7 13 8 20. 64
Binary Coded Decimal code In computing and electronic systems, binary-coded decimal (BCD) (sometimes called natural binary-coded decimal, NBCD) is an encoding for decimal numbers in which each digit is represented by its own binary sequence Its main virtue is that it allows easy conversion to decimal digits for printing or display, and allows faster decimal calculations. Its drawbacks are a small increase in the complexity of circuits needed to implement mathematical operations Many non-integral values, such as decimal 0.2, have an infinite place-value representation in binary (.001100110011...) but have a finite place-value in binary-coded decimal (0.0010). Consequently a system based on binary-coded decimal representations of decimal fractions avoids errors representing and calculating such values. 65
BCD The BIOS in many personal computers stores the date and time in BCD because the MC6818 real-time clock chip used in the original IBM PC AT motherboard provided the time encoded in BCD. This form is easily converted into ASCII for display. In BCD, a digit is usually represented by four bits which, in general, represent the values /digits / characters 0 9. 66
BCD 10 11 12 13 14 15 0001 0000 0001 0001 0001 0010 0001 0011 0001 0100 0001 0101 67
Addition in BCD The same as binary rules, but some times the result need some correction if we get a number greater than 9. Example: 9 1001 + 8 1000 00010001 illegal code > 9 To be legal code we correct it by adding 6 0001 0001+0110=0001 0111 68
Subtraction in BCD The same rules as binary with correction 6 if the subtrahend > Minuend. Example: 52-24=28 0101 0010-0010 0100 0010 1110 illegal code >9, so subtract 6-0110 1000 69
Excess-3 code Excess-3 binary-coded decimal (XS-3), also called biased منحازة التمثيلrepresentation or Excess-N, is a numeral system used on some older computers that uses a pre-specified number N as a biasing value. It is a way to represent values with a balanced number of positive and negative numbers. In XS-3, numbers are represented as decimal digits, and each digit is represented by four bits as the BCD value plus 3 (the "excess" amount): 70
Excess-3 code 71
Gray code The reflected binary code, also known as Gray code after Frank Gray, is a binary numeral system where two successive values differ in only one bit. The reflected binary code was originally designed to prevent spurious output from electromechanical switches. Today, Gray codes are widely used to facilitate error correction in digital communications such as digital terrestrial television and some cable TV systems. 72
73
From binary to Gray The most significant bit of the binary code is the same most significant bit in Gray code Add each two successive digits from the left to produce new gray digit, carry is discarded. Example (1100) 2 =( ) g (1 ) g ---- (10 ) g -----(101 ) g ----- (1010) g 74
From gray to binary The most significant bit of the gray code is the same most significant bit in binary code Add this digit to the next digit in the gray cod,( diagonally addition) for all bits. Example (101110101) g =( ) 2 (1 ) 2 --- (11 ) 2 --- (110 ) 2 ---- (1101 ) 2 --- (11010 ) 2 ------ (110100110) 75
Alpha- Numerical code (ASCII) American Standard Code for Information and Interchange. Many applications of digital computers require handling of data that consist not only of numbers, but also of letters. Numbers : 0-9 (10 numbers) Small letters : a-z(26 letters) Capital letters : A Z (26 letters) Special characters :?,!, #,.. (32 characters) all of 94 elements 2 6 =64, 2 7 =128 7 bit 76
ASCII-table 77