Download Binary Numbers

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Mathematics of radio engineering wikipedia , lookup

Principia Mathematica wikipedia , lookup

Bra–ket notation wikipedia , lookup

Abuse of notation wikipedia , lookup

Location arithmetic wikipedia , lookup

Addition wikipedia , lookup

Musical notation wikipedia , lookup

History of mathematical notation wikipedia , lookup

Positional notation wikipedia , lookup

Large numbers wikipedia , lookup

Big O notation wikipedia , lookup

Arithmetic wikipedia , lookup

Elementary mathematics wikipedia , lookup

Transcript
Review end of last class file compression/speed, etc
Binary Numbers
Review binary numbers. 0, 1, 1, 0, etc.
Review - Characters values are stored as ASCII. Hello. = 01001000
01100101 01101100 01101100 01101111 00101110
Unicode 16 bits – 65,536 different bit patterns – Chinese, Japanese,
etc can be represented.
In order to allow arithmetic operations, numbers cannot be stored as
ASCII. They are stored using excess notation or two’s complement
for integers and floating-point notation for decimal-numbers.
Signed Numbers
The leftmost bit is used to indicate the sign of the number:
0 - positive
1- negative
Signed Integer – leftmost signbit is 0 if the number is positive or 0,
and 1 if it’s negative.
(Largest 16 bit integer is 32,767 (2 to 15 power – 1). 32-bit is 2,147,483,647 (2
to 31 power – 1).)
Negative numbers are represented in two’s complement form.
Two’s complement notation: The most popular system for
presenting integers within today’s computers is two’s
complement notation. Each value is represented by a pattern of
32 bits. Such a large system allows a wide range of numbers to
be represented.
-231 = -2,147,483,648
840950735
1
231 – 1 = 2,147,483,647
Example of smaller systems:
Using patterns of length three:
(starts 0000 counts up till 0 followed by 111s is reached, and
counts backwards in binary until a 1 followed by 0s is reached. )
left most is sign bit.
Bit pattern
Value represented
011
3
010
2
001
1
000
0
111
-1
110
-2
101
-3
100
-4
(patterns complement each other – change all 0s to 1s and 1s
to 0s).
Using patterns of length four:
Bit pattern
0111
0110
0101
0100
0011
0010
0001
0000
1111
1110
1101
1100
1011
840950735
Value Represented
7
6
5
4
3
2
1
0
-1
-2
-3
-4
-5
2
1010
1001
1000
-6
-7
-8
Excess notation: Also for integers:
Bit Pattern
111
110
101
100
011
010
001
000
Value Represented
3
2
1
0
-1
-2
-3
-4
excess four notation – exceeds the excess notation interpretation
by the value 4.
An excess eight conversion table
Bit Pattern
1111
1110
1101
1100
1011
1010
1001
1000
0111
0110
0101
0100
0011
0010
0001
0000
840950735
Value Represented
7
6
5
4
3
2
1
0
-1
-2
-3
-4
-5
-6
-7
-8
3
Ex: 1100 normally represents 12, but in our system it represents
4. 0000 normally represents 0, in our system it represents -8.
Real numbers (e.g., 256.78) use floating point notation to
represent the mantissa and the exponent of the number.
0 – nonnegative 1 - negative
256.78 = 2.5678 x 102
01101011
0 = positive
110 = exponent
1011 = mantissa
.1011
110 = 2 (in three bit excess method)
move 2 over to the right. (-2 would be to the left).
10.11
and nonnegative, so it’s 2 ¾.
Another example:
10111100
mantissa .1100
exponent 011= -1
.01100
1 is negative
so -3/8 (011 = 3/8)
Reverse:
1 1/8
840950735
4
1.001
mantissa
____1001
.1001 we need to move one bit to the right.
101 (positive 1 in excess four notation)
0 because nonnegative
01011001
Round-off Error/Truncation Error
2 5/8 is 10.101. But it’s too big for the mantissa field in one-byte
floating-point system. And the rightmost 1 (represents last 1/8) is
lost. Instead of 10101 being stored, it’s 1010 in the mantissa field.
(01101010) Which represents 2 ½ instead of 2 5/8.
You can reduce the problem by using a longer mantissa field. Most
computers today will use at least 32 bits for storing values in floatingpoint notation instead of the 8 bits here. This also allows for a longer
exponent field.
840950735
5