Upload
daisy-townsend
View
217
Download
0
Embed Size (px)
Citation preview
Review Binary Basic Conversion
Binary 128 64 32 16 8 4 2 1 Decimal
7
0110 0010 0 1 1 0 0 0 1 0
38
1101 0001 1 1 0 1 0 0 0 1
129
1010 1010 1 0 1 0 1 0 1 0
182
0000 1111 0 0 0 0 1 1 1 1
255
Review Binary Conversion of decimals
2 1 . .5 .25 .125 .0625 .03125 Decimal
11.10001 1 1 . 1 0 0 0 1
. 2.0625
00.01100 0 0 . 0 1 1 0 0
. 1.53125
10.00011 1 0 . 0 0 0 1 1
. 0.875
Review Binary Conversion of non-standard decimals
◦ Note: Remember to convert the whole number separatelyNumber Whole
NumberPart number
0.22 x 2 =
x 2 =
x 2 =
x 2 =
x 2 =
x 2 =
x 2 =
Number Whole Number
Part number
1.15 x 2 =
x 2 =
x 2 =
x 2 =
x 2 =
x 2 =
x 2 =
• Solution: • Solution:
Binary 2NEGATIVE NUMBERS
bits Each 0 or 1 is a bit of information
Bit = binary digit
A bit is a single piece of information
A nibble is 4 bits of information
A byte is 8 bits of information
A word refers to a string of bits used is a process by a computer. Eg. A computer might work in 8, 16 or 32 bit words.
bits When we talk about representing a number using 5 bits, it means we have five 0’s and 1’s01001 (9)
In binary we’ll typically work with 8 bits0100 0001 (65)
As they are strings of bits, we might refer to any of these as a ‘word’◦ A 5-bit word◦ An 8-bit word
bits In representing a number there are bits that are sometimes referred to as:
◦ Most Significant bit◦ Least Significant bit
Most significant bit◦ Left most bit◦ In the position for the largest value number
Least significant bit◦ Right most bit◦ In the position for the lowest value number
10001Most significant bit – value 16Least significant bit – value 1
What about negative numbers? How might we represent negative numbers using only 0s and 1s?
Let’s consider...◦ Unsigned Binary◦ Sign & Magnitude◦ Two’s Complement
Unsigned Binary This is binary in the format we have already dealt with
◦ Deals with positive numbers only◦ No extra bits
Sign and Magnitude Sometimes referred to as signed binary
Deals with positive and negative numbers
Reserves a bit (the most significant bit) as a ‘sign bit’
Sign bit is used to indicate a positive number (0) or a negative number (1)
0 101 is + 5 (positive)
1 101 is - 5 (negative)
Sign and Magnitude Using Sign and Magnitude (with 1 sign bit, and 7 bits for the number), convert the following numbers
Binary Decimal
0 000 1011
1 000 1100
10
-65
-18
1 111 0010
85
Sign and Magnitude Using Sign and Magnitude, convert the following numbers
Binary Decimal
0 000 1011 11
1 000 1100 -12
0 000 1010 10
1 100 0001 -65
1 001 0010 -18
1 111 0010 -114
0 101 0101 85
Two’s Complement Two’s complement is also used to represent positive and negative numbers.
It does not use a sign bit, however the most significant bit does act as an indicator for the sign of the number
The two’s complement of a number is the negative representation of a number
Two’s Complement ‘Taking a two’s complement’ means getting the negative representation of a number
The easiest way to do this:◦ Start with the positive representation of the number◦ Start from the right most bit and work towards the left◦ Any ‘0’ bits remain the same until the first ‘1’ bit◦ Keep the first ‘1’ bit as a 1◦ Change every other bit to its opposite (10 and 01)
Two’s Complement– Start with the positive
representation of the number– Start from the right most bit
and work towards the left– Any ‘0’ bits remain the same
until the first ‘1’ bit– Keep the first ‘1’ bit as a 1– Change every other bit to its
opposite (10 and 01)
6 is 0000 0110
0000 0110
0000 0110 0000 0110
1111 1010
Two’s complement Follow the steps to determine the 8-bit two’s complement representation of -5 and -10
Original Binary Representation
Two’s Complement New Value
5
10
Two’s complement Follow the steps to determine the 8-bity two’s complement representation of -5 and -10
Original Binary Representation
Two’s Complement New Value
5 0000 0101 1111 1011 -5
10 0000 1010 1111 0110 -10
Two’s Complement Important Note!!!
You only need to ‘take the two’s complement’ if ◦ the number is negative, or◦ the number needs to be subtracted
Always start with more bits than you require to represent the number.◦ Eg. 4 can be represented using just 3 bits, to complete two’s complete accurately you must work with at
least 4 bits or more