Data Representation and Number Systems Flashcards
How to convert from decimal to base-R?
Whole numbers: divide by R until quotient hits 0. The remainder forms the base-R representation where the first remainder is the LSB and the last remainder is the MSB.
Fraction: multiply by R until product is either zero or a pattern is repeated. The carry over forms the base-R representation where the first carry over is the MSB and the last is the LSB.
Using a random number generator twice, convert the first number into the base representation of the second number
Check using https://www.rapidtables.com/convert/number/base-converter.html
How to do base conversion for normal cases?
Convert to decimal first then convert from decimal to target base.
What are some special cases for base conversions?
- Binary to octal: partition into groups of 3
- Octal to binary: split each number into a group of 3 numbers
- Binary to hexadecimal: partition into groups of 4
- Hexadecimal: split each number into a group of 4 numbers
What are the 3 common representations for negative binary numbers? And explain how to get each.
- Sign-and-magnitude, MSB acts as sign bit where 0 is positive and 1 is negative.
- 1s complement, invert all bits.
- 2s complement, invert all bits then add 1.
Formula to get (r - 1)’s complement, a.k.a radix diminished complement? Where n is the number of integer digits, m the number of fractional digits and N is the number to be represented
r^n - r^(-m) - N
Formula to get r’s complement, a.k.a radix complement? Where n is the number of integer digits and N is the number to be represented
r^n - N
How to perform addition and subtraction for 2s complement?
Addition: A + B, ignore the carry out of MSB and check for overflow. Overflow happens when ‘carry in’ and ‘carry out’ of MSB is different or sign is different from A and B.
Subtraction: A + (-B), get the 2s complement for B then add it to B.
How to perform addition and subtraction for 1s complement?
Addition: A + B, if there is a carry out of the MSB, add 1 to the result. Check for overflow which happens when the result is different sign with A and B
Subtraction: A + (-B), get the 1s complement for B then add it to A.
What is ‘Excess Representation’
A way to represent negative numbers using simple translation
What are the two ways to represent floats?
Fixed point representation (number of bits allocated for integer and fraction portion is fixed) and floating point representation which has 3 components: sign, exponent and mantissa.
Using a random number generator twice, convert the first number into binary fixed point representation with the second number as the size of integer portion. The size of the binary number is 16 bits.
Check using https://www.rfwireless-world.com/calculators/floating-vs-fixed-point-converter.html
Using a random number generator, convert this number into IEEE754 format.
Check using https://www.h-schmidt.net/FloatConverter/IEEE754.html