lecture 6 Flashcards
information encoding
machine language
binary numbers only
binary encoding
convert data into different form or representation
base-10
decimal numbers
0-9
base-2
binary
0-1
base-16
hexidecimal
0-9, A-F
base-10 equation
v = Σ (10^i)(d)
*key:
v –> base-10 value
i –> digit position (increases right
to left starting @ 0)
d –> decimal digit
what is each base-10 digit multiplied by?
power of 10
base-10 example)
173
1 7 3
= 173
how is this equal to 173?
1 7 3
10^2 + 10^1 + 10^0
= 1(10^2) + 7(10^1) + 3(10^0)
= 173
base-2 equation
v = Σ 2^i bi
*key:
v –> base-2 number
i –> digit position (increasing
from right to left, starting @
0)
b –> binary digit (either 1 or 0)
what is each base-2 digit multiplied by?
power of 2
base-2 example)
011111010000
= 2000 (base-10)
how is this equal to 2000?
0 1 0 0 1 0 0 1
2^7 2^6 2^5 2^4 2^3 2^2 2^1 2^0
= 1(2^6) + 1(2^3) + 1(2^0)
= 64 +8 +1
= 73
what is the most significant bit?
msb –> always going to be the greatest power of 2
(right most bit)
what is the least significant bit?
lsb –> always going to be the lowest power of 2
(left most bit)
0 1 0 0 1 0 0 1
2^7 2^6 2^5 2^4 2^3 2^2 2^1 2^0
what is the msb?
2^7
- greatest power of 2 (right most bit)
0 1 0 0 1 0 0 1
2^7 2^6 2^5 2^4 2^3 2^2 2^1 2^0
what is the lsb?
2^0
- least power of 2 (left most bit)
**always going to be 2^0
decimal to binary algorithm
v/2 = quotient, remainder = bit (going to be 0 or 1)
quotient/2, remainder = next bit (going to be 0 or 1)
STEPS:
divide v by 2
remainder becomes next bit
quotient becomes next v
**repeat until v = 0
- msb –> last bit found when v
= 0
- lsb –> first bit found
* first division –> remainder = lsb
* last division –> remainder = msb
base-16 equation
v = Σ 16^i d
*key:
v –> base-10 value
i –> digit position (increasing from
right to left, starting @ 0)
d –> hexit
base-16 0-9 chart
0 - 0
1 - 1
2 - 2
3 - 3
4 - 4
5 - 5
6 - 6
7 - 7
8 - 8
9 - 9
base-16 A-F chart
10 - A
11 - B
12 - C
13 - D
14 - E
15 - F
what is each base-16 digit multiplied by?
power of 16
how many bits is one hexit digit?
4 bits
if you are converting binary to hexit, how do you go about doing this?
break up the binary digits every 4 digits starting at the lsb (leftmost bit)
- in each of these segments, the
digits’ indexes are from 2^0 to
2^3
- do the usual calculation and that’s
the hexit representation
binary to hexit example)
011111010000
= 0x7D
how does this work?
011111010000
A) break up the binary into groups of 4
0111 1101 0000
B) calculate what number each 4 digits add up to
0000 = 0
1 1 0 1
2^3. 2^2. 2^1. 2^0
= 8 + 4 + 1
= 13 –> D
0 1 1 1
2^3. 2^2. 2^1. 2^0
= 4 + 2 + 1
= 7
C) put it together
011111010000 = 0x7D
ASCII encoding allows what
conversion from character to number
what is signed magnitude representation?
used to encode positive and negative binary numbers
are the positive and negative binary representations different in signed magnitude?
no
what is the difference between positive and negative binary reps in signed mag?
msb (most significant bit)
- msb = 0, positive number
- msb = 1, negative number
range for values able to be represented in signed magnitude rep
-(2^N-1 - 1) to (2^N-1 - 1)
N = # of bits
pros of signed magnitude
easy to negate
easy to compute abs value
cons of signed magnitude
add/subtract is complex
2 different ways of repping 0
+0 and -0 –> two different things
what is signed magnitude used for?
floating point representation
**not integers
what is the two-step process for 2’s complement?
- complement every bit
- 1 –> 0, 0 –> 1 - add 1 (binary addition)
** if neg –> pos rep
**if pos –> neg rep
range for 2’s complement
(-2^N-1) to (2^N-1 -1)
N = # of bits
is 2’s complement the same process for negating a negative binary number?
yes
is adding the same thing as subtracting in 2s complement?
yes
what is sign extension?
when you pad the binary number with 0s or 1s (to preserve the sign) if you need it to be an “extended”/bigger amount of bits
pros of 2s complement
only add operation
only one zero rep
sign extension
cons of 2s complement
more complex to negate and compute abs value
floating point rep
(sign) (significand) x 2^(exponent)
- sign –> positive and negative number determinant
- normalized fraction (significand)
- exponent (position of the “floating” binary point)
what is IEEE 754 floating point rep?
used to represent double/float numbers (fractions)
sign field (s) –> 1 bit
- 0 : pos, 1 : neg
exponent field (E)
- 8 bits (exponent + 127)
fraction field –> 23 bits
- 23 bits significand w/o leading 1
*1 –> hidden (normalized)
IEEE 754 floating point rep steps
- convert to binary
- 4 bits on either side of decimal place - normalize the fraction to 1.F
- move it until its 1.F - calculate the exponent
- based on how many places you moved to normalized –> E - 127
- convert to binary