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.

  • It uses 10 digits.
  • Each position corresponds to .
  • For example, .
Link to original

Binary

Binary is a **base-2** numbering system.

  • 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 original
  • Nibble

    A nibble is a series of four bits.

    Link to original
Link to original

Radix notation

Radix notation is a way we write numbers to distinguish different bases.

  • is a decimal number.
  • is a binary number.
Link to original

Prefix notation

We can also use prefix notation, we indicate the base preceding the number:

  • is a binary number.
  • is a Hexadecimal number.
Link to original

Link to original

3. Base conversions

Base conversions

There are two common approaches for base conversions:

  • 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.

Link to original

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.

  • For example in binary is to 5 bits of accuracy.
Link to original

5. Signed-magnitude binary

Signed magnitude

Signed-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:

  • Sign bit makes it difficult to perform arithmetic.
  • There are two representations of .
Link to original

Link to original

8. Hexadecimal

Hexadecimal

Hexadecimal

Hexadecimal is a **base-16** numbering system.

  • 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.
Link to original

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:

  • Group into nibbles:
  • Convert each nibble to decimal:
  • Translate to hex characters:
  • Hence
Link to original

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