Interpreting Bits

Recall the idea of Bits:

What is a Bit?

BIT - BInary digiT

A bit is an ‘entity’ having two distinct, distinguishable, discrete states. Generically designated as and .

A bit can be realized by any physical object that has two stable states that can be distinguished confidently.

  • Think of a transistor’s on and off state — when passing current, the bit is , when no current, the bit is
  • Additionally, think of a CAN bus, there is no off or on state, but rather a low and high voltage to differentiate. One line runs usually at 2.5v and the other usually around 5v, differences between both wires can be interpreted as or because they are predictable and stable.
Link to original

Representations of Bits

We denote the set

The cartesian product of with itself creates bit tuples:

    • So, the nibble is . Generically
  • We write homogeneous tuples as bit vectors, using [] rather than ()
    • So, we say . Generically
  • We can also get rid of the commas and enclosing []

Shorthand Representations of Bits

  • Instead of writing bit vectors, we can write
  • We create new symbols for bit vectors
    • 2 bit sequences:
    • 3 bit sequences:
    • 4 bit sequences:
  • Use prefix to indicate notation: 0b, 0x
  • Use _ to separate groups of symbols
    • E.g., 0x0000_4a6b_8192_4000
  • Note: you cannot use the 0b and _ syntax in C.
Intepretation
000
011
102
113

Specifying Interpretations

  • Mappings from representations to values are called codes or interpretations
  • The most general way to specify a code is by enumeration (similar to a cookbook)

Most codes we come across aren’t formulaic or algorithmic, which won’t work for a computer system.

We want to be able to represent our codes in a value set.

Thats why we move to weighted codes.

Weighted Codes

Weights represent the value of a bit at each position.

So in binary, we know bits to be , where is the position of the bit from the left.

Ex: How many inches in 7 yards, 2 feet, 5 inches?

We could go about this the long way, manually doing every calculation through dimensional analysis. OR, we could represent the case as a weight vector:

. In this case:

Weights: . In this case, (these are the number of inches in each unit, respectively)

Value: .

Positional Codes

If the weights can be written as a simple function of positions (), the function is sufficient to specify the weight vector

  • Representation: , Weight:
  • Value:

This gives a positional binary representation of the integer range

  • This mapping is bijective
  • Bit is said to be less significant than bit if
  • Extend this to define more significant, least significant, and most significant

Radix-k (Base-k) Positional Codes

Generalize from binary to other bases

  • Representation: with
  • Weight:
  • Value:

An approach to converting bases

Say we’re given the number in base-10 (decimal).

How can we convert this to base-16 (hexadecimal)?

Just keep dividing by 16 and add the remainder’s last digit.

Base 16 to base 2

Convert each digit separately to be binary.

Including Negative Integers

Note: represents unsigned integers using 6 bits, represents signed integers using 6 bits

Can we make the range of values rather than ?

Two Solutions

  • Simple method:
    • Not a weighted code
    • This is called “biasing”
  • Another way: Change the weight vector to
    • This is called the “two’s complement” representation

Range Expansion

Given a -bit vector , we want to expand it to a )-bit vector and re-interpret as an integer.

  • Moving from a smaller -bit wheel to a larger -bit wheel

Expansion:

  • Unsigned:
  • Signed:

Re-interpretation: and represent the same integer

  • Unsigned: proof is obvious
  • Signed: proof by induction, is the base case, divide it into two cases based on the value of

Range Truncation

Given a -bit vector , we want to truncate it to a -bit vector where and re-interpret as an integer

  • Moving from a larger -bit wheel to a smaller -bit wheel

Truncation:

Re-interpretation:

  • Unsigned: if represents , then represents
  • Signed: if represents , then represents , where has the same representation on the signed -bit wheel as does on the unsigned -bit wheel.

To understand this, lets look at a few calculations

Remainder and Modulus

Given an integer and non-zero integer :

  • We write . is also non-negative

Special Bit Operations

Because we express bits as in binary, we can do special operations with them. Often called bitwise operations. There are many Operations on Representations to look over.