Binary Representation Flashcards
Bit
Bit: “Binary digiT,” a basic unit of information in a computer
○ 1 bit = a bit
○ 4 bits = a nibble
○ 8 bits = a byte
Digital
finite number of symbols (opposite is “analog” i.e. continuous)
Signed Magnitude
MSB tells sign of number. No further adjustments
001 = 1
101 = -1
Issue:
- two numbers for 0
- arithmetic not straight forward. Does not work.
1C
Flip all digits, to obtain negative of unsigned number
001 = 1
110 = -1
issue:
- two numbers for 0
- Hardware to perform addition is tricky to implement
2C
1C + 1 to obtain negative of unsigned number.
Alternative approach: copy bits from right to left up to and including the first “1” and flip remaining bits
Advantage:
- only one representation for zero
- computer can add positive and negative numbers together
Floating Point
○ sign, fraction, and exponent
○ N = (-1) S × 1.fraction × 2^(exponent-127)
1__10000001__10101000000000000000000
S__Exponent__Fraction
Unsigned overflow
Operation results goes beyond the width of memory location in a computer/ width of machine
Signed overflow
positive + positive number -> negative
negative + negative number -> positive
ASCII - Size
2^7 = 128 combinations
UNICODE - Size
2^32 combinations
How do calculations with fractions in binary work
2C addtion and stubtraction still work. To do this, allign binary points
Word
bits computer can process in one operation
Multiplication of two n bit numbers. Result how many bits
2n
Addition of two n bit numbers. Result how many bits
up to n+1
Largest and smallest number that can be represented with n bits in 2C
Largest: 2^(n-1)-1
Smallest:-2^(n-1)
Sign Extension
Used when adding number of different length
Extend MSB of shorter number for 2C
Extend with 0 in case of unsigned numbers
Encoding
Agreed upon ‘mapping’ of data from one representation to another
Examples: ASCII, UNICODE
Hexadecimal
fewer digits. More compact and convenient than binary
Just a notation, not a different machine representation
Why do we use bias ‘127’ in floating point standard
- Allows us to have a very big range for the exponent from (-127 to 128)
- allows us to represent very big an very small numbers w/o using 2c for the exponent
- Allows us to speed up comparison of floating point numbers. –> Exponent is a 8 bit UNSIGNED number. Easier to compare then if we would need to convert in 2C. The “larger” the exponent number the bigger the number, negatively or positively depending on the Sign.
Special Cases IEEE Floating point number
Number 0: Sign = X, Exponent = 0, Fraction =0
Number +Infinity: Sign = 0, Exponent = 11111111, Fraction =0
Number -Infinity: Sign = 1, Exponent = 11111111, Fraction =0
Number NaN: Sign = X, Exponent = 11111111, Fraction =Not Zero
Number: -1^s x 0.fraction x 2^(-126) . Case if exponent = 0 and fraction = not zero
How many two input logic functions are possible?
4 input combinations. For every input combination I can assign 0 or 1 as output. i.e. 2^4 = 16