Download presentation
1
Review Two’s complement
2
Negate a Binary Number in 2C
Negation means to find the corresponding negative number with the same absolute value (in decimal the Negation of 10 is –10) The method is the same whether you negate a positive to a negative or vice versa and doing it twice should give you the same result: -(-a) = a Method: Invert the binary number (“flip all bits”) Inverse ( ) = Add to the result binary 1 (append 0’s on the left) = =
3
Convert Decimal to 2C Decimal to Binary (word length k = 8):
If positive: Fraction number into a sum of powers of 2 bin(13)=8+4+1= = If Negative: Fraction the negated number and negate binary number (invert and add 1) bin(-13) = Negate(bin(13)) = Negate( ) = Invert( ) = =
4
Convert 2C to Decimal Binary to Decimal (word length k=8):
If most significant bit (left most) is 0 the number is positive: Sum the powers of 2 Dec( )=0*27 +0*26+1*25 +0*24 +1*23 +1*22 +0*21 +1*20 =1*128+0*64+1*32+0*16+1*8+1*4+0*2+1*0 =173 If most significant bit (left most) is 1 the number is negative, that means you can not just add the powers of 2 Find the decimal value of the negated binary number and negate it back in decimal (putting a – in front) Dec( ) = - (Dec(Negate( )) = - (Dec(Invert( ) )) = - (Dec( )) = - (Dec( )) - now it is a positive number and we can sum the powers of 2! = -( ) = - 83
5
Operations on 2C Addition: bitwise including carry as in decimal
Negation: Invert and add 1 Subtraction: Addition of Negated operand: A – B =A + (– B) Multiplication by 2: Shift left * 2 = Division by 2: Shift right ÷ 2 =
6
Issues: Binary Numbers
Signed Extension: Sometimes we are lazy and don’t write out all bits. In 2C you can only add 0’s to the left if the number is positive, otherwise you make a negative number positive: -3 = for k=4 = for k=8 For negative number you have to add 1’sto the left! Overflow: If the result of an addition/subtraction is bigger than the biggest or smaller than the smallest possible number of word length k Can never happen if you add a positive and a negative number
7
Hexadecimal Numbers Decimal Hex Binary 0000 1 0001 2 0010 3 0011 4 0100 5 0101 6 0110 7 0111 8 1000 9 1001 10 A 1010 11 B 1011 12 C 1100 13 D 1101 14 E 1110 15 F 1111 Same principle as decimal and binary but with a base of 16 Number has a little x to the side: xF5 Motivation: Word size is either 32 or 64, that are very long binary numbers, in Hex you can save space: Conversion from Hex to binary is simple in blocks of 4(this works because 16=24): x5B2F = To decimal (if positive): = 5* * * *160 = = 23343
8
LOGICAL OPERATORS A B AND 0 0 0 1 1 0 1 1 1 A B OR 0 0 0 1 1 1 0 1 1
0 0 0 1 1 0 1 1 1 A B OR 0 0 0 1 1 1 0 1 1 A B XOR 0 0 0 1 1 1 0 1 1 AND: is only 1 if all inputs are 1 OR: is 1 if any of the inputs is 1 XOR: is 1 if either input is 1 NOT: is the inverse (“flip the bit”) A NOT 1
9
Logic on Words and Multiple Input
AND OR
10
Text Data: ASCII Code ASCII is a 7 bit encoding scheme for all keyboard symbols and some additional ones Digits: x30 to x39 Uppercase: x41 to x5A Lowercase: x61 to x7A Conversion: Table Question: How can you mathematically convert a lowercase letter into uppercase?
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.