Académique Documents
Professionnel Documents
Culture Documents
What is a Register?
Numerical Overflow
Example: In order to store a 9-bit number (101010000) in an 8-bit register, two 8-bit
registers have to be taken up (i.e. it would overflow if put in one 8-bit register:
Left Shift
Shifting a binary number left by 1 bit means inserting a 0 to the right, so that this
becomes the new least significant bit:
Right Shift
Shifting a binary number right by 1 bit NOTE THAT WHEN SHIFTING A BINARY
means deleting the present least significant NUMBER TO THE RIGHT, AND A 1 IS DELETED,
bit, irrespective of whether this is a 1 or a 0, SINCE THAT WAY DATA IS LOST, THE VALUE
so that the bit next to it, (on the left), MAY NOT BE EXACTLY HALVED.
becomes the new significant bit:
Page 1 K Aquilina
Student Notes Theory
Binary Addition
When adding binary numbers we must keep in mind that we can use only the binary
digits 1 and 0. In decimal addition we carry 1 when the total of a column is 10 or more
since the base is 10. In binary addition, we carry 1 when the total of a column is 2 since
the base is 2.
• 0 + 0 = 0
• 0 + 1 = 1
• 1 + 0 = 1
• 1 + 1 = 0, and carry 1 to the next more significant bit
• 1 + 1+ 1 = 1, and carry 1 to the next more significant bit
Exercise 1:
= 38(base 10)
= 81(base 10)
Unsigned Integers
Unsigned integers are positive numbers together with zero ( 0 ).
3 bits =
4 bits =
5 bits =
6 bits =
N bits -------------------
Page 2 K Aquilina
Student Notes Theory
Signed Integers
Signed integers are ALL whole numbers i.e. Positive, Negative numbers and Zero.
Sign-magnitude representation uses the most significant bit of the number to indicate the
sign. A negative number is the 7-bit binary representation of the positive number with the
most significant bit set to one.
0110 1001
msb is 0 so positive msb is 1 so negative
( 01102 = +610 ) ( 10012 = -110 )
As seen in class, the drawbacks to using this method for arithmetic calculations are that
a different set of rules are required and that zero can have two representations (+0,
0000 0000 and -0, 1000 0000).
Exercise 2:
One’s Complement
To convert to 1s complement:
Invert all bits of the number (1s are changed to 0s and 0s to 1s )
Two’s Complement
To convert to 2s complement:
a. Invert all bits of the number (1s are changed to 0s and 0s to 1s)
b. Add 1 (The msb is the sign)
For example,
Page 3 K Aquilina
Student Notes Theory
Property
Two's complement representation allows the use of binary arithmetic operations
on signed integers, yielding the correct 2's complement results.
Positive Numbers
Positive 2's complement numbers are represented as the simple binary.
Negative Numbers
Negative 2's complement numbers are represented as the binary number that
when added to a positive number of the same magnitude equals zero.
Note: The most significant bit indicates the sign of the integer; therefore it is sometimes called the
sign bit. If the sign bit is zero, then the number is greater than or equal to zero, or positive. If the
sign bit is one, then the number is less than zero, or negative.
0000
1111
-1 0 0001
1110 -2 1
0010
1101
2
-3
3 0011 2's complement
1100 -4 in a 4-bit register
4 0100
1011 -5
5 0101
1010 -6 6 0110
-7 7
1001 -8 0111
1000 most positive
number
most negative
number
Example
Page 4 K Aquilina
Student Notes Theory
Exercise 3:
Example 1: 5 + (-3)
0000 0010 = +2
Example 2: 7 - 12
1111 1011 = -5
Summary
Binary notation can be used to store any data type in memory
We have learned how to represent
o Characters
o Integer numbers (positive and negative numbers)
Notes
Binary Number System
Bit (short for binary digit): A single binary digit 0 and 1
LSB (least significant bit): The rightmost bit
MSB (most significant bit): The leftmost bit
Binary Equivalents
1 Byte = 8 bits
1 Kilobyte (KB) = 1024 bytes = 210 bytes
1 Megabyte (MB) = 1024 kilobytes = 1024 x 1024 bytes
1 Gigabyte (GB) = 1024 megabytes = 1,073,741,824 bytes
Page 5 K Aquilina