Binary -ve and +ve numbers!
Objectives 3.1.2 Understand how computers represent and manipulate numbers [unsigned integers, signed integers (sign and magnitude, Two’s complement) real numbers] 3.1.3 Be able to convert between binary and denary whole numbers (0-255) and vice versa
Recap How do you convert positive denary numbers into positive binary numbers? 32 75 123 128 64 32 16 8 4 2 1 0100100
You have to learn 2 ways… There are a number of ways of representing negative numbers in binary. You need to know Sign and magnitude Two’s Compliment.
Sign and Magnitude When working with positive, and especially negative denary numbers you will see two things. - 12 Magnitude! Sign! Don’t forget the number 32 is actually +32 We use our intelligence to recognise there should be a + sign even if there isn’t!
sign and magnitude representation In this approach, the problem of representing a number's sign can be to allocate one sign bit to represent the sign: Setting that bit (often the most significant bit) to 0 is for a positive number or positive zero, and setting it to 1 is for a negative number or negative zero.
Watch teacher demonstration Are we wasting bits? Hence, in a byte with only seven bits (apart from the sign bit), The magnitude can range from 0000000 (0) to 1111111 (127). Thus numbers ranging from −12710 to +12710 can represented once the sign bit (the eighth bit) is added. Watch teacher demonstration
Another problem… A consequence of this representation is that there are two ways to represent zero, 00000000 (0) and 10000000 (−0).
Signed and Unsigned Unsigned 1100 Signed 0 1100 0 = a positive number 1 = a negative number 11000100 = 10000001 = 00011110 = 10011111 = -68 -1 62 -31
Two’s Complement To understand how this might work, imagine a brand new car with it’s odometer set to 0000 If you drive forward 1 mile it would be come 0001 What if you could reverse for 1 mile? It would say 9999
An Example 3 00000011 2 00000010 1 00000001 00000000 -1 11111111 -2 11111110 -3 11111101
Two's complement. The problems of multiple representations of 0 are circumvented by a system called two's complement. In two's complement, negative numbers are represented by the bit pattern which is one greater (in an unsigned sense) than the ones' complement of the positive value.
Converting a number. In two's-complement, there is only one zero, represented as 00000000. Negating a number (whether negative or positive) is done by inverting all the bits and then adding 1 to that result.
Two’s Compliment -30 Step 1) Start off with the positive number 0001 1110 Step 2) Invert the bits 1110 0001 Step 3) You need to add one to the final number 1110 0010
Plenary What are the 2 methods for representing negative numbers? What number is the following 10011? What is two’s complement? Why is two’s complement needed?