Module 2: Binary Representation Flashcards
bit
“binary digit”
1 bit = a bit
4 bits = a nibble
8 bits = a byte
digital
finite number of symbols (opposite is analog)
weighted positional representation
a positional number system represents numeric values as sequences of one or more digits. each digit in the representation is weighted according to its position in the number
unsigned numbers
positive numbers and zero
signed numbers
negative numbers, zero, and positive numbers
unsigned overflow
when an operation result goes beyond the width of memory location in a computer
signed overflow
when you add 2 positive numbers and get a negative result or if you add 2 negative numbers and get a positive result
sign extenstion
when performing arithmetic operations on numbers of different width we must sign-extend numbers (which means “replicating the sign bit” 0 or 1 before the number of smaller width) before performing operations so that both numbers are the same width
encoding
“encoding” data simply means an agreed upon “mapping” of data from one representation to another
Binary digital system
absence of voltage and presence of voltage
OFF/ON
0 or 1
EVERYTHING is sequences of 0s and 1s
Non-negative integers in binary
representation of integer in binary
subtraction, multiplication, and division also similar to base 10
note: n-bit multiplication produces 2n-bit results
overflow example: 15+1 with 4-bit integers (16 needs 5 bits 10000)
in this example, our computer has a 4-bit width and we’ve gone past it
negative integers in binary
sign-magnitude: place a “1” in front of a number:
0001 is “+1”
1001 is “-1”
leading # indicates the sign of the number
1C: take the positive representation of a binary number and flip aka “complement” each bit
- assuming 4-bit width
- +5 in 1C: 0101 (must pad with leading 0)
- -5 in 1C: 1010 (simply flip each digit)
2C: 1C + 1 and omit any resulting carry-out past the width of the machine
- +5 in 2C would be 0101 (must pad with leading 0)
- -5 in 2C would be 1011 (add one to get the 2C)
- advantage: only 1 representation of 0
- computers can add positive and negative numbers together
converting numbers to/from 2C
copy bits from right to left up to and including the first “1” and flip remaining bits
sign extension
if a number is positive (leading 0) pad with 0s
if a number is negative (leading 1) pad with 1s
encoding
ASCII: American Standard Code for Information Interchange
2^7 = 128 combinations
UNICODE = 2^32 possibilities
Hexadecimal representation
01101101 = 0110 1101 = x6D
Fractions in binary
2C addition and subtraction still work
To do this, we align the binary points
Floating-point
sign, fraction, and exponent
N = (-1)^s x 1.fraction x 2^(exponent-127)