Unsigned Integers
• Represents positive integers only
• Example: ASCII character codes
• Not necessary to indicate a sign, so all 8 or 16 bits can be
used for the magnitude:
– 1 byte = 8 bits = 28 = 256 (0 to 255)
– 2 bytes = 16 bits = 216 = 65,536 (0 to 65,535)
– 4 bytes = 32 bits = 232
= 4,294,967,296 (0 to 4,294,967,295)
Signed Integers
 Represents positive and negative integers
… -2, -1, 0, 1, 2, …
 MSB (Most Significant Bit – leftmost bit) used to indicate
sign
0 = positive, 1 = negative
 One less bit is used for the magnitude, with one extra
negative value
1 byte = 8-1 bits = 27 (-128 to +127)
2 bytes = 16-1 bits = 215 (-32,768 to +32,767)
4 bytes = 32-1 bits = 231 (-2,147,483,648 to
+2,147,483,647 )
Signed Integers
 Let consider the binary:
I I 0 0 0 I I 0
Convert it to decimal number.
 Use positional representation as shown previously with one change in
the MSB
-27 * 1 = -128
26 * 1 = 64
25 * 0 = 0
24 * 0 = 0
23 * 0 = 0
22 * 1 = 4
21 * 1 = 2
20 * 0 = 0
-128 +(64+4+2)=58
Signed Integers
Some values of interest (8-bit example):
• +0
0 0 0 0 0 0 0 0
• +1
0 0 0 0 0 0 0 I
• -1
I 0 0 0 0 0 0 0
I I I I I I I I
Signed Integers
Some values of interest (8-bit example):
• Max positive value
0 I I I I I I I = 127
• Most negative value
I 0 0 0 0 0 0 0 = -128
1’s & 2’s Complement
• 1’s complement form
– Formed by reversing (complementing) each bit
• 2’s complement form
– Formed by adding 1 to 1's complement
– Negative numbers are stored this way
• Additive inverse of a number
• Computer never has to subtract
• A – B = A + (-B)
Signed Integers (8-bit)
 Example: -9
1. 0000 1001b
2. 1111 0110b
+1b
1111 0111b
247
 Example: -32
1. 0010 0000b
2. 1101 1111b
+1b
1110 0000b
224
Class Exercise
• Convert the following negative decimal
numbers to 8 bit binary using the 2’s
complement
– -1, -3, -8, -17
Class Exercise
• Evaluate 25 + (- 5) in 8 bit binary
– Convert 25 to binary
– Convert -5 to 2’s complement
– Add together
– Check your answer by converting back to decimal

1 number systems-unsignedsignedintegers

  • 1.
    Unsigned Integers • Representspositive integers only • Example: ASCII character codes • Not necessary to indicate a sign, so all 8 or 16 bits can be used for the magnitude: – 1 byte = 8 bits = 28 = 256 (0 to 255) – 2 bytes = 16 bits = 216 = 65,536 (0 to 65,535) – 4 bytes = 32 bits = 232 = 4,294,967,296 (0 to 4,294,967,295)
  • 2.
    Signed Integers  Representspositive and negative integers … -2, -1, 0, 1, 2, …  MSB (Most Significant Bit – leftmost bit) used to indicate sign 0 = positive, 1 = negative  One less bit is used for the magnitude, with one extra negative value 1 byte = 8-1 bits = 27 (-128 to +127) 2 bytes = 16-1 bits = 215 (-32,768 to +32,767) 4 bytes = 32-1 bits = 231 (-2,147,483,648 to +2,147,483,647 )
  • 3.
    Signed Integers  Letconsider the binary: I I 0 0 0 I I 0 Convert it to decimal number.  Use positional representation as shown previously with one change in the MSB -27 * 1 = -128 26 * 1 = 64 25 * 0 = 0 24 * 0 = 0 23 * 0 = 0 22 * 1 = 4 21 * 1 = 2 20 * 0 = 0 -128 +(64+4+2)=58
  • 4.
    Signed Integers Some valuesof interest (8-bit example): • +0 0 0 0 0 0 0 0 0 • +1 0 0 0 0 0 0 0 I • -1 I 0 0 0 0 0 0 0 I I I I I I I I
  • 5.
    Signed Integers Some valuesof interest (8-bit example): • Max positive value 0 I I I I I I I = 127 • Most negative value I 0 0 0 0 0 0 0 = -128
  • 6.
    1’s & 2’sComplement • 1’s complement form – Formed by reversing (complementing) each bit • 2’s complement form – Formed by adding 1 to 1's complement – Negative numbers are stored this way • Additive inverse of a number • Computer never has to subtract • A – B = A + (-B)
  • 7.
    Signed Integers (8-bit) Example: -9 1. 0000 1001b 2. 1111 0110b +1b 1111 0111b 247  Example: -32 1. 0010 0000b 2. 1101 1111b +1b 1110 0000b 224
  • 8.
    Class Exercise • Convertthe following negative decimal numbers to 8 bit binary using the 2’s complement – -1, -3, -8, -17
  • 9.
    Class Exercise • Evaluate25 + (- 5) in 8 bit binary – Convert 25 to binary – Convert -5 to 2’s complement – Add together – Check your answer by converting back to decimal