Presentation is loading. Please wait.

Presentation is loading. Please wait.

Topic 3: Data Signed Binary.

Similar presentations


Presentation on theme: "Topic 3: Data Signed Binary."— Presentation transcript:

1 Topic 3: Data Signed Binary

2 Positive and Negative Numbers
There are all kinds of numbers out there Positive ones Negative ones Whole ones Fractional ones Rational ones Irrational ones Real ones Imaginary Ones A computer needs to know how to store each of these in binary form We’re going to focus on positive and negative numbers

3 Positive and Negative Numbers
We know, almost instantly, when a number is positive or negative 10: Positive -5: Negative More technically, we can tell if a number is negative if there is a minus sign in front of it If there is no sign, we assume the number is positive Computers can’t assume It needs to know, definitively, if a number is positive or negative To do this, scientists have come up with different methods

4 Signed/Unsigned Integers
Let’s start with the idea behind signed and unsigned integers Integer: whole number If an integer is unsigned, it does not care about positivity or negativity Unsigned integers can only ever be positive No bits are wasted for a sign If an integer is signed, it can be positive or negative A bit needs to be used for the sign though

5 Signed/Unsigned Integers
Take this example We have a number: 610 (is 1102 in binary) If this is an unsigned integer, we can leave it as 1102 If it is signed, we need to use 01102 The most-significant bit acts as the sign 0: Positive 1: Negative Ultimately, state that the unsigned version only takes 3 bits to store, but the signed version needs 4 bits. If space on a computer is especially tight (not so much of a problem these days), then using unsigned integers can save a bit of space now-and-again.

6 Sign and Magnitude The signing system earlier is called sign and magnitude When we use 1 bit for the sign, and the other bits for the number The sign bit is always the most-significant bit Here are some examples 1 Sign Bit Usual Binary Value Note that, for each of the examples shown, an extra bit is added on the far left for the sign. 1010 = = 11111 -4 = = 11000

7 Write the following denary values in sign and magnitude binary
15 25 -50 100 -255 32 -16 -1 ANSWERS From top-left to bottom-right:

8 Two’s Complement The range of values allowed in sign and magnitude can be found using the following So a 4-bit sign and magnitude binary number has the range -7 to 7 There is another system we can use Two’s Complement 𝑟𝑎𝑛𝑔𝑒=± ((2 𝑛 −1 ) −1) 𝒏 is the number of bits

9 Two’s Complement The Two’s Complement and sign and magnitude are nearly identical Both use most-significant bit for sign However, in Two’s Complement, the most- significant bit is not just the sign It represents the negative of that bit’s value Note that we calculate the result as usual – by adding up the denary value of each bits. However, in this case, the most-significant bit is the negative of its usual value. We can calculate the denary value of the table on the slide by adding the denary value of each bit (as usual): (-8 x 1) + (4 x 0) + (2 x 0) + (1 x 1) = = -7 Denary -8 4 2 1 Binary

10 – + Two’s Complement Here’s an example of some signed binary numbers
We can still have positive numbers in this system 0110 0010 0000 1000 0100 1100 1010 1110 1011 1001 1101 1111 0101 0111 0011 0001 + +6 +2 +4 +5 +7 +3 +1 -8 -4 -6 -2 -5 -7 -3 -1 -8 4 2 1 Denary 3 -4 -1

11 Two’s Complement Converting any denary number into Two’s Complement is easy First convert to unsigned binary If the number is negative, then Flip all the bits (0’s to 1’s, and 1’s to 0’s) Add 1 to least significant bit Negative Example Denary Number: -4 1) Unsigned Binary: 100 2) Two’s Compliment: 0100 Still add 0 as we haven’t added the minus sign yet 3) Flipped Bits: 4) Add 1 to LSB: 1100 Positive Example Denary Number: 4 1) Unsigned Binary: 100 2) Two’s Compliment: 0100 Added 0 to show that number is positive

12 Convert the following denary numbers into Two’s Complement signed binary numbers
8 7 -3 -14 1 -1 ANSWERS From top-left to bottom-right:

13 Two’s Complement We have two methods for converting Two’s Complement binary numbers to denary Method 1: Multiply digits by their worth, and add together Method 2 (only needed if negative): Flip bits, add 1, and then use Method 1 Method 1 Two’s Compliment: 1) Find values: (32 x 0) + (16 x 1) + (8 x 1) + (4 x 0) + (2 x 1) + (1 x 0) 2) Sum values: = 26 Method 2 Two’s Compliment: negative number, so we use Method 2 1) Flip bits: 2) Add 1 to LSB: 3) Find values: (32 x 0) + (16 x 0) + (8 x 0) + (4 x 1) + (2 x 1) + (1 x 0) 4) Sum values: = 6 5) Add sign: -6 needed as binary number was negative We don’t have to use Method 2 if we don’t want to. We can just as easily sum the denary value of the binary digits manually (as shown on Slide 9).

14 Convert the following Two’s Complement signed binary numbers to denary
1100 0101 1001 010011 110011 111111 ANSWERS From top-left to bottom-right:

15


Download ppt "Topic 3: Data Signed Binary."

Similar presentations


Ads by Google