The position of each symbol encodes a weighting factor that is the base number raised to the power of the position. Fractional values are similarly represented by considering positions after the decimal point as negative indexed positions.
By convention, we call the left most digit the most significant digit as it is associated with the largest weighting factor. Similarly, the right most is called the least significant digit. Note that arithmetic between two numbers may change the number symbols required for representation, ex. .
What is the largest number we can represent with only 3 digits?
The use of 10 symbols in our decimal number system is somewhat arbitrary. What happens when we change our alphabet size to 2, i.e. ? How would we represent our familiar decimal numbers?
Again, the weighting factor is base of our number system (2) raised to the power of the symbol's position. We call the symbols in binary bits.
We've already seen how to convert from binary to decimal using weighting factors. How about from decimal to binary? An intuitive way is to start with the largest power of 2 that fits into the number, and keep including powers of 2 until you've met the decimal number,
It's best to keep binary in groups of four bits for legibility, hence the leading zero.
A more algorithmic method for binary to decimal is to repeatedly divide the decimal number by two, recording the remainder, until zero is reached.
Hence, .
Binary fractions: sucessive multiplication.
What' the largest number you can represent with bits?
Note that hexadecimal and octal have alphabet sizes of 16 and 8 respectivley. Our arabic digits don't go past nine, so we have to start using new symbols for hex.
An easy way to convert between hex and binary is by dealing with groups of 4 bits. Similarly octal numbers and 3 bits.
BCD represents each digit in a number separately in 4 bit binary.
decimal BCD
------- --------------
950 <--> 1001 0101 0000
1011
does not correspond to any decimal symbol. It is useful for displaying information and interfacing with displays.
The same tools of arithmetic you're familiar with in decimal carry over to other number systems. Most importantly, the tool of "carrying" extra symbols from one position to the next significant position when addition overflows.
to extend your understanding, try:
hex/octal addition/subtraction (without converting to binary)
binary multiplication
(hint) work through examples in decimal if you're stuck
How can we represent negative numbers? In everyday (decimal) life we use an extra symbol, the negative sign, ex. . We call this representation sign-magnitude, and in binary it is represented by the MSB indicating the precense of a negative sign a.k.a the sign-bit.
Given bits, what's the range of numbers spanned by a sign-magnitude representation?
Another (more common) way of representing sign in binary is via Two's Complement. In this representation, the weighting factor of the MSB is given a negative sign. Negation is conviently achieved by flipping bits and adding one.
This has the following benefits over sign-magnitude:
no negative zero, larger range
subtraction is equivalent to negation + addition (only one circuit required: addition)
We verify that addition arithmetic works two's complement numbers. Note that the final carry bit is ignored by design.
decimal sign-mag. 2's comp. decimal
------- ----------- ----------- --------
carry: 111 1 1
45 => 0010 1101 => 0010 1101
- 23 - 0001 0111 + 1110 1001
==== =========== ===========
22 10001 0110
ignore overflow: 0001 0110 => 22
A downside of two's complement is that underflow/overflow must be manually checked before computation begins, as opposed to being indicated via a carry bit. This is due to the "wrap-around" nature of the representation which is required for its nice arithmetic properties. For example, in two's complement,
bit: binary symbol (0 or 1)
byte: 8 bits
nibble: half a byte, 4 bits
kilo-byte (KB): 1,000 bytes = 8,000 bits
kilo-bit (Kb): 1,000 bits
How fast will a 100 MB file download over your 100 Mbps internet connection?