1. Overview
Overview
Any data stored in a computer is stored as binary. For example, a stored image is broken down into pixels which is broken down into integer values which is then broken down into bytes.
Link to original
2. Positional number systems
Positional numbering system
Decimal system
The decimal system is typically used by humans for representing numbers, it is a **base-10** numbering system.
Link to original
- It uses 10 digits.
- Each position corresponds to .
- For example, .
Binary
Binary is a **base-2** numbering system.
Link to original
- It uses two binary digits (bits), typically and .
- Each position corresponds to .
- For example, .
Byte
A byte is a series of eight bits.
Link to originalNibble
A nibble is a series of four bits.
Link to originalRadix notation
Radix notation is a way we write numbers to distinguish different bases.
Link to original
- is a decimal number.
- is a binary number.
Link to originalPrefix notation
We can also use prefix notation, we indicate the base preceding the number:
Link to original
- is a binary number.
- is a Hexadecimal number.
3. Base conversions
Base conversions
There are two common approaches for base conversions:
Link to original
Subtraction: start from the largest bit and work your way downwards subtracing values as you go down the powers. (standard method)
Divison-remainder: divide by each time, taking the remainder as the binary number.
This method allows us to easily convert to any base.
4. Fractional components
Numbers in any base can have a fractional component.
- (decimal point)
- (binary point)
We can use negative powers to easily convert these components:
- Take for example, .
- We just continue in the downward trend:
Some fractional components may have an infinite series of digits in other bases.
- For example, will never terminate in binary.
- Or, .
As such, we may not always be able to accurately convert fractional components to other bases. A simple way we use to deal with loss of accuracy is to specify how many digits of accuracy you are using.
Link to original
- For example in binary is to 5 bits of accuracy.
5. Signed-magnitude binary
Signed magnitude
Link to originalSigned-magnitude binary
Signed magntiude is where negative numbers can be represented by specifying a sign in the [[Most significant bit|most significant bit]].
For example:
- signed magnitude is .
- signed magnitude is .
Advantages:
- Signed magnitude is simple and intuitive.
- It’s easy to convert unsigned numbers to positive signed values.
Disadvantages:
Link to original
- Sign bit makes it difficult to perform arithmetic.
- There are two representations of .
8. Hexadecimal
Hexadecimal
Hexadecimal
Hexadecimal is a **base-16** numbering system.
Link to original
- It uses 16 digits, 0 to 9 and then A to F.
- Each position corresponds to .
- Since , it is easy to convert between binary and hex.
To convert a binary number to hexadecimal (or back):
- We group each part of the binary number into groups of 4 bits (a Nibble).
- Convert each separate nibble to decimal.
- Each nibble translates to one hexadecimal character.
For example, to convert to hex:
Link to original
- Group into nibbles:
- Convert each nibble to decimal:
- Translate to hex characters:
- Hence
9. Why binary
Why binary?
Binary is used due to the physical properties of hardware that we use.
- Modern computers use transistors that can either be on or off, best represented by binary.
- It’s also efficient for computing the logic of computation, such as boolean logic.
Before the discovery of electricity, mechanical computers used cogs and gears instead of electronic transistors. Hence, these usually used decimal or ternary.
Quantum computers don’t use transistors, and quantum logic doesn’t consider two states like Boolean logic.
Link to original