Bits and Data

CS-A1120 Programming 2

Lukas Ahrenberg

Department of Computer Science
Aalto University

(Based on material by Petteri Kaski and Tommi Junttila)

Module I - the mystery of the computer

  • Aim: to study the principle of a computer - bottom up
    • How to represent data
    • How to build logic circuits that operate on data
    • How to use clocked feedback in circuits
    • How to program a computer without a high-level language (assembly)

We will build this in Scala by using classes that represents logical components. In the end, working on a simulated processor.

After this lecture

  • You will have familiarity with binary and hexadecimal numbers
  • You will think of data as sequences of bits, and know some basic data types
  • You know the syntax of Boolean operations and shift operators on integer data types in Scala
  • You will be aware of the IEEE 754 floating point number standard

See this week's reading material for even more information!

Analog and Digital

  • Analog : using continuous phenomena
  • Digital : using discrete set of states

While there has been analog computers, both historical and modern, commercial computers today are digital.

google-data-center.jpg

Google data center
Source: Google gallery

Antikythera-mechanism.jpg

Source: Wikipedia CC 2.5 Generic

Digits

  • Digit = finger/toe
  • The decimal number system has ten digits: 0,1,2,3,4,5,6,7,8,9
  • The binary system has two: 0,1

Bits

  • Bit (short for "binary digit")
  • Basic unit for representing information

zero-and-one.png

Claude E. Shannon A mathematical theory of communication (1948) reports that J. W. Tukey introduced "bit" to represent a number 0 or 1 in a binary numeral system.

Binary numbers

  • Computing is easy in the binary numeral system
    • Only two states for the machine to tell apart
    • Multiplication is easy (not tables to memoize)
  • Binary and Hexadecimal numbers are part of general knowledge for a programmer

Representing natural numbers (integers)

  • The number "754" can be represented in various ways:
    • Roman numerals: DCCLIV
    • Decimal numerals: 754
    • Binary numerals: 1011110010

The Decimal and Binary representations are both examples of positional number systems with different base (or radix).

Positional number systems

  • In a positional number system we have a set of symbols, the size of which we call the base or radix
    • In our usual decimal number system this is 0,1,2,3,4,5,6,7,8,9, meaning we have base 10
    • In the binary number system we use 0,1, and the base is 2
    • In programming we also use the hexadecimal number systems, usually with the symbols 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F, and thus base 16

Note: The symbols are not important For base \(n\) we only need a order of \(n\) different symbols (states). What they are isn't that important (decimal in 0-9 or why not A-J, binary in 0 or 1, or green and blue, or …)

Interpreting positional numbers

  • We write out the number as a string, where the least significant digit is the rightmost, and the most significant digit is the leftmost,
  • and calculate the value of a position as \(b^i\) where \(b\) is the base, and \(i\) is an index starting from \(0\) at the least significant digit
    • For example: \(754 = 700 + 50 + 4 = 7 \times 10^{2} + 5 \times 10^{1} + 4 \times 10^{0}\)
    • The same is possible when interpreting binary data as a decimal number:
\begin{gather*} \left(1011110010\right)_{2} = 1 \times 2^{9} + 0 \times 2^{8} + 1 \times 2^{7} + 1 \times 2^{6}\\ + 1 \times 2^{5} + 1 \times 2^{4} + 0 \times 2^{3} + 0 \times 2^{2} + 1 \times 2^{1} + 0 \times 2^{0}\\ = 512 + 128 + 64 + 32 + 16 + 2\\ = 754\\ \end{gather*}

From binary to decimal

  • As we have see, we can use the same 'formula' as for decimal numbers, but with base 2.
  • Or, expressed as an algorithm:
    • Input, base 2 number \(x \in \mathcal{Z}_{\geq 0}\)
    • Initialize result to value \(0\)
    • Repeat for every bit position \(j \geq 0\)
      • if bit \(j \) is 1 then
        • Add \(2^{j}\) to result
  • Example: \(\left(11001\right)_2 = 2^0 + 2^3 + 2^4 = 25\)

From decimal to binary (algorithm)

  • Input, base 10 number \(x \in \mathcal{Z}_{\geq 0}\)
  • Initialize all bits in the result to 0 (off)
  • Repeat until \(x = 0\)
    • Find the largest possible \(y = 2^j\) such that \(x - 2^j \geq 0\)
    • Set bit \(j\) to 1 (on)
    • Update \(x\) to \(x - y\)

Example: Convert 25 to binary

  1. Initially \(x = 25\), \(res = 0\)
  2. Find largest \(2^j \leq 25\)
    • This is \(y = 16\), so \(j = 4\)
    • Set bit 4 to 1: \(res = \left(10000\right)_2 \)
    • Update: \(x = 25 - 16 = 9\)
  3. Find largest \(2^j \leq 9\)
    • This is \(y = 8\), so \(j = 3\)
    • Set bit 3 to 1: \(res = \left(11000\right)_2\)
    • Update: \(x = 9 - 8 = 1\)
  4. Find largest \(2^j \leq 1\)
    • This is \(y = 1\), so \(j = 0\)
    • Set bit 0 to 1: \(res = \left(11001\right)_2\)
    • Update: \(x = 1 - 1 = 0\)
  5. \(x = 0\) so we end

The final result is \(\left(11001\right)_2\)

Data

bit-sequence.png

  • Information in computing is represented as sequences of bits ("data")
  • The basic measure of amount of data is the number of bits in the sequence

What does data represent ?

  • A sequence of bits is just a string of zeroes and ones
  • What makes the sequence of bits interesting is the conventions and standards on what the sequence represents

bit-sequence.png

\(29058\) bits

Take a particular sequence of 29058 bits (which doesn't fit in one line or on the page):

111111111111111111111110001111101111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111000000111001111111111111111111111111111101111110111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110111000110011110111100111011111111111111011111101111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111001111100100111011111000110011111100111110111111011011111011101111100011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110111111101011100111101100110111111011111101111100110111110011001110000111000011111111111001111111111111111111111111111111111111111111111111111111111111111111111111111001111111010110011111011101100111101111111011111001001111110110001101101110110011100111110011111111111111111111111111111111111111111111111111111111111111111111111111110111111110100011111110111011101110011111110111110010011111101101010110011101110111000111101111111111111111111111111111111111111111111111111111111111111111111111111111101111111100000111111101110011001101111111101111101100111111011010001100111111101110110111101111111111111111111111111111111111111111111111111111111111111111111111111111011111111000000011111000000111000111111111011111011001111111110110111001101111011101101111011111111111111111111111111111111111111111111111111111111111111111111111111110111111110001110011100001101110001111111110000000110011111011101111110011011110111011101110111111111111111111111111111111111111111111111111111111111111111111111111111100111111001011110011011111011110111111111101111101101111110111011111100110111101111011011101111111111111111111111111111111111111111111111111111111111111111111111111111001111110110111110110111110011101111111111011111011011111101100111111011100000001110110011011111111111111111111111111111111111111111111111111111111111111111111111111111001111001101111100101111110111011111111110111110110011110011001111110111001111011101110110111111111111111111111111111111111111111111111111111111111111111111111111111111001100111011111100011111101110111011111101111101110111101110011111101110111110111011100100111111111111111111111111111111111111111111111111111111111111111111111111111111000011110111111110111111011101110111111011111011100100111100111111001001111101110111101001111111111111111111111111111111111111111111111111111111111111111111111111111111011111111111111111111111111111001111111111111111100011111111111111010011111001101111000111001111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110111111111111111111111111111111111111111111111011011111001111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111011111111111111111111111111111111111111111111111110111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111101111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111101111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111100111111111111111111111111111111111111111111111111111111111111111001111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111001111111111011111111111111111111111110111111111111111111111111110011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110011111101110111111111111111111111000000011111111111111111111111110111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111100111111011101111110110011111111100111110111111111111111111110011101111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111001111110110011111101110111111011011111110111111111111111111100011011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111011111101100111111001101111110111111111001111111111111111111100000011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110111111011011111110011011111101111111110111111111111111111111001001111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111101111100110111111110110111111011111111011111111111111111111111011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111000000001101111111011101111110111111000111111111111111111111110111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110001110011011111110111000000001111100111111111111111111111111101111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111101111110110111111101110000000011111001111111111111111111111111101111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111011111101110111111011101111110111110011111111111111111111111111011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110111111011101111110111011111101111110111111111111111111111001110111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111101111110111011111011110111111011111111111111111111111111110001101111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111001111100110011000111101111110111111111111111111111111111101101011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110111111111111000111111011111101111111111111111111111111111011100111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111011111000111111111111111111110111101111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110111110011111111111111111111101111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111101111111111111111111111111111111111111111111111110111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110011111111111111111111111111111111111111111111111101111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111101111111111111111111111111111111111111111111111111011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110011111111111111111111111111111111111111111111111110111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111101111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111100111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111011111111111111111111111111111111111111111110110000110011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111100111111111111111111111111111111111111111111000001100000000001100000000001111111111111111111001111110111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111011111010111111110011111101100011011111111000000111111101111110111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110111110100111111110111110111110110000001110111111111111101111101100111111111111011111111111111111111111111111111111111111111111111111111111111111111111111111111111111101111011101111111101111101111110101111101101111111111111001111010000011101111110111111111111111111111111111111111111111111111111111111111111111111111111111111111111111011100111011111111011111011111110011111011011111111111111001101001110011011111101111111111111111111111111111111111111111111111111111111111111111111111111111111111111110100000110000111110111101111111100111100111011111111111111010010111110010111111101111111111111111111111111111111111111111111111111111111111111111111111111111111111111101111110101111111101100011111111001110111110001111111111111001101111110101111111011111111111111111111111111111111111111111111111111111111111111111111111111111111111111011111101011111111000010111111110100011111100000111111111110011011111101011111110111111111111111111111111111111111111111111111111111111111111111111111111111111111111110111111010111111110111101111111111000111111011111111111111101110111111010111111101111111111111111111100000000111111111111111111111111111111111111111111111111111111111101111101101111111101111101111110110110011110111111111111111101101111110101111110111111111111111111100111111110001111111111111111111111111111111111111111111111111111111011111011011111111011111011111101101110111101111111111111111010111111011011111101111111111111111110011111111111100111111111111111111111111111111111111111111111111111110111101110000000110111111011110111011110111011111111111111110100111110110111111011111111111111111011111111111111110111111111111111111111111111111111111111111111111111100000111111000111101111111011001110111101110000000111111111101101111011110111110111111111111111100111111111111111110111111111111111111111111111111111111111111111111111111111111111111111111111111000111111111011100011111111111110011001101111100111011111111111111111011111111111111111110111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111100111111110001111111111111111100111111111111111111110111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111011111111111111111111110111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111101111111111111111111111111111111111111111111111111111111111111111111011111111111111111111111101111111111111111111111111111111111111111111111111111111111111111111111110111111111111111111111111111111111111111111111111111111111111111111110111111111111111111111111011111111111111111111111111111111111111111111110111111111111111111111111101111011111111111111111111111111111111111111111111111110111111111111101111111111111111111111110111111111111111111111111111111111111111111111001111111111111111111111111111100111111111111111111111111111111111111111111111111110111111111111011111111111111111111111101111111111111111111111011111111111111111111111011110111110000000000111111110110110011111111111001111000011111111111111111111111100111111111110111111111111111111111111011111111111111111111100001111111111111111111110111101110111100111111111111011101000000110011100011001111011011101111110111110011101111111111001111111111111111111111110111111111111111111111011011111111111111111111001111011101111011111111111100111110111101100111010010111110010111011111100000001111111111111110011111111111111111111111101111111111111111111110110111111111111111111110111110111011110111111111111011111011111101000101110101111110101110111111001111111111111111111101111111111111111111111111011111111111111111111101101111111111111111111101111101110111101111111111101111110111111010100011101011111001011101111110011111111111111111111001111111111111111111111111111111111111111111111011011111111111111111111000000011101111011111111111011111111111110101101111010111110110111011111110111111111111111111110011111111111111111111111011111111111111111111110110111111111111111111110000000111011110111111111110111110111111101011111101101111011101110111111100000111111111111111100111111111111111111111110111111111111111111111101100011111111111111111101111101110111101111111111011111101111111010111111011010000111011101111111000111111111111111111101111111111111111111111101111111111111111111111011110111111111111111111011111011011111011111111110011111011111110101111110110110111110111011111110111111111111111111111011111111111111111111110111111111111111111111100101101111111111111111110011110110111110111111111110111110111111011011111101101111111101110111111101111111101111111111110111111111111111111111101111111111111111111111011010111111111111111111101111101100111101111111111101111110111110110111111011011111111011101111111011111111001111111111100111111111111111111111011111111111111111111110110101111111111111111111011111011001111011111111111011111100110011101111110110111111110111000000100111111110011111111111101111111111111111111101111111111111111111111101101011111111111111111111111111111111110111111111111011001110011111111111111101111111101110011100100000001100111111111111011111111111111111111011111111111111111111110111010111111111101111111111111111111111101111111111110000111111111111111111111111111111111111111111000011111011111111111111011111111111111111101111111111111111111111101110011111111110011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110111111111111110011111111111111110011111111111111111111111011010111111111100111101111111111111111111111111111111111111111111111111111111111111111111111111111111111111011111111111111110011111111111111001111111111111111111111110110101111111110001110011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111011111111111100111111111111111111111111011101011111111010011001111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110001111111110011111111111111111111111110111011111111110100100111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111101001111110011111111111111111111111111101110011111110011011011111110011111101110000001111111111111111111111111111111111111111111111111111111111111111111111111111111110011100000011111111111111111111111111111011010111111101110001111111100111111011101111110000011111000000011111111111111111111111111111111111111111111111111111111111111101111111111111111111111111111111111111110110101111111111110111111111011111110110011111100100000000001110110011111110111111111111111111111111111111111111111111000011111001111111111111111111111111111111111111001101011111111111111111111110111111101100111111111101111101111111110111111101111111110111110111111111111111111111111110111011110011111111111111111111111111111111111110111010111111111111111111111101111111011001111111111011111011111111100111111011111111101111101100000000111111111111111001110011100011111111111111111111111111111111111101110101111111111111111111111011111110111000000111110111110111111111001111110111111110011111001001111101111111111111110111110111000011111111111111111111111111111111111011011011111111111111111111110111111101111111101111101111101111111111001111101111111100111111010111111101111111111111101111110110100111111111111111111111111111111111110110101111111111111111111111001111111011111111011111011111011011111101011110111111111001111110101111111011111111111111011111101101000111111111111111111111111111111111101101011111111111111111111110111111110111111110011110111110000111111011011101111111110011111101011111100111111111111110111111001011010111111111111111111111111111111111011010111111111111111111111101111111101111111100111101111101111111100110111011111111110111111010111111011111111111101101111111010110110111111111111111111111111111111110110101111111111111111111111001100111011011111011111011110111111111001110110111111111101111110100000000111111111111011011111110001110101111111111111111111111111111111101001011111111111111111111110000011110111011101111110111100111111110111101101111111111011111011000000111111111111110110111111100011101101111111111111111111111111111111010110111111111111111111111111111111111111000111111101111000000000000111101011111111110111110110111111111111111111100001111111000111001101111111111111111111111111111110101101111111111111111111111111111111111111111111111011111000001111011111000111111111100111011101111111111111111110001011111110001111011001111111111111111111111111111101010011111111111111111111111111111111111111111111111111110111111111111111011111111111100110111011111110011111111100110111111110011110111001111111111111111111111111110110000111111111111111111111111111111111111111111111111111111111111111111111111111111111100011110111111001111111111001101111111100111100111001111111111111111111111111101100001111111111111111111111111111111111111111111111111111111111111111111111111111111111111111101111111111111111110101011111111001111101111001111111111111111111111111010001011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111101010111111110011111011111001111000000000001111111110100011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111010100111111100111111011111000000111111111000011111011010110111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111100101101111111001111110111111001111111111111111111110000101101111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111100000011111110011111100111111111111111111111111111100001011011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110010111111000111111100011111111111111111111111111111110111011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111101100111110101111111110001111111111111111111111111011000010011111111111111111100000000000000111111111111111111111111111111111111111111111111111111111111111111111111111011101111101011111111111000111111111111111111111000000010010000000011010000001111111111111000111111111111111111111111111111111111111111111111111111111111111111111111110111011110010011111111111100011111111111110000000000000000010000000000000111111110001000000001111111111111111111111111111111111111111111111111111111111111111111111111111110011101100111111111111110001111111111100111111011111111101111111100000000000111001111110101111111111111111111111111111111111111111111111111111111111111111111111111111110111011001111111111111111000111111111001111111111111111111111111111111111111111111111001011111111111111111111111111111111111111111111111111111111111111111111111111011110101110011111111111111111100011111110000000000000000000000000000000000000000000000000010011111111111111111111111111111111111111111111111111111111111111111111111110111110011100111111111111111111111001111111111001111111111111111111111111111111111111111100110111111111111111111111111111111111111111111111111111111111111111111111111101111111111001111111111111111111111100001111110011111111111111111111111111111111111111111011101111111111111111111111111111111111111111111111111111111111111111111111111011111111111011111111111111111110111110000111110111111111111111111111111111111111111111110111001111111111111111111111111111111111111111111111111111111111111111111111110111111111110111111111111110000000111111110011001111111111111111111111111111111111111111101110011111111111111111111111111111111111111111111111111111111111111111111111101111111111100111111100000000111100111111000000011111111111111111111111111111111111111111011100111111111111111111111111111111111111111111111111111111111111111111111111011111111111100000000011111111111101111110111101111111111111111111111111111111111111111110111011111111111111111111111111111111111111111111111111111111111111111111111111011111111111000000000000000000000000000101100011111111111111111111111111111111111111111101110111111111111111111111111111111111111111111111111111111111111111111111111110111111111111111111111111111111111001100000110111111111111111111111111111111111111111111011101111111111111111111111111111111111111111111111111111111111111111111111111101111111111111111111000000000011111011011111101111111111111111111111111111111111111111110111011111111111111111111111111111111111111111111111111111111111111111111111111011111111110000000000011111111001110010011111011111111111111111111111111111111111111111101101111111111111111111111111111111111111111111111111111111111111111111111111110111111100000111111111111111111001110110111110111111111111111111111111111111111111111111011011111111111111111111111111111111111111111111111111111111111111111111111111101111110011111111111111111111111001100011111101111111111111111111111111111111111111111110110111111111111111111111111111111111111111111111111111111111111111111111111111011110011111111111111111111111111011100111111011111111111111111111111111111111111111111101101111111111111111111111111111111111111111111111111111111111111111111111111110011101111111111111111111111111110011101111110111111111111111111111111111111111111111111011011111111111111111111111111111111111111111111111111111111111111111111111111110111011111111111111111111111111110111001111101111111111111111111111111111111111111111110110111111111111111111111111111111111111111111111111111111111111111111111111111101110111111111111111111111111111001110011111011111111111111111111111111111111111111111101101111111111111111111111111111111111111111111111111111111111111111111111111111011110111111111111111111111111110111100111110111111111111111111111111111111111111111111011011111111111111111111111111111111111111111111111111111111111111111111111111110111110011111111111111111111110011111000111101111111111111111111111111111111111111111110110111111111111111111111111111111111111111111111111111111111111111111111111111101111110000001111111111111110001111101101111011111111111111111111111111111111111111111011101111111111111111111111111111111111111111111111111111111111111111111111111111101111111111100000000000000001111111011011110111111111111111111111111111111111111111110111011111111111111111111111111111111111111111111111111111111111111111111111111111011111111111111101101111111111111100110011101111111111111111111111111111111111111111101110011111111111111111111111111111111111111111111111111111111111111111111111111110000000000011110011011111111111111011110111011111111111111111111111111111111111111111101100111111111111111111111111111111111111111111111111111111111111111111111111111111111111100000000000011111111111100111101110111111111111111111111111111111111111111111011101111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111000000111111111111011111101101111111111111111111111111111111111111111110111011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110111011111111111110111111011011111111111111111111111111111111111111111101110111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111001110111111111111001111110010111111111111111111111111111111111111111111011101111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110111101111111111110111111110101111111111111111111111111111111111111111111011011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111101111011111111111001111111101011111111111111111111111111111111111111111110110011111111111111111111111111111111111111111111111111111111111111111111111111111111111111110011110111111111110111111111010111111111111111111111111111111111111111111101110111111111111111111111111111111111111111111111111111111111111111111111111111111111111111101111101111111111101111111111100111111111111111111111111111111111111111111011101111111111111111111111111111111111111111111111111111111111111111111111111111111111111110011111001111111110011111111111001111111111111111111111111111111111111111110111011111111111111111111111111111111111111111111111111111111111111111111111111111111111111101111111011111111101111111111110111111111111111111111111111111111111111111101110111111111111111111111111111111111111111111111111111111111111111111111111111111111111111011111110111111110011111111111101111111111111111111111111111111111111111111001101111111111111111111111111111111111111111111111111111111111111111111111111111111111111101111111101111111101111111111111011111111111111111111111111111111111111111110011001111111111111111111111111111111111111111111111111111111111111111111111111111111111110011111111001111111111111111111110111111111111111111111111111111111111111111100111011111111111111111111111111111111111111111111111111111111111111111111111111111111111101111111111011111111111111111111101111111111111111111111111111111111111111111101110011111111111111111111111111111111111111111111111111111111111111111111111111111111110010010111110011111111111111111111011111111111111111111111111111111111111111111011110111111111111111111111111111111111111111111111111111111111111111111111111111111111100000000000000011111111111111111110111111111111111111111111111111111111111111110111100111111111111111111111111111111111111111111111111111111111111111111111111111111100111111111111110011111111111111111101111111111111111111111111111111111111111111100000000011111111111111111111111111111111111111111111111111111111111111111111111111110011000000000001110011111111111111111011111111111111111111111111111111111111111111001110000000011111111111111111100000000101111111111111111111111111111111111111111111000000011111111100000011111111111111110111111111111111111111111111111111111111111110000000111111000000000000110001111111111100000000111111111111111111111111111111111100101111111111111111100011111111111111101111111100011111111111111111111111111111111001110111111111111111111111111111111111111111111111111111111111111111111111111111111011101111111111111110000111111111111111000000000000000000000000000000000000000000000011111111111111111111111111111111111111111111111111111111111111111111111111111111111010011111111111111101101111111111111110001111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110001111111111111111011011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110001111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111

This could be intepreted as a very large integer number, or..

\(29058 = 167 \times 174\) bits

Divided in to 174 rows, each of 167 columns:

11111111111111111111111000111110111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111 11111111111111111111110000001110011111111111111111111111111111011111101111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111 11111111111111111111110111000110011110111100111011111111111111011111101111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111 11111111111111111111100111110010011101111100011001111110011111011111101101111101110111110001111111111111111111111111111111111111111111111111111111111111111111111111111 11111111111111111111101111111010111001111011001101111110111111011111001101111100110011100001110000111111111110011111111111111111111111111111111111111111111111111111111 11111111111111111111001111111010110011111011101100111101111111011111001001111110110001101101110110011100111110011111111111111111111111111111111111111111111111111111111 11111111111111111111011111111010001111111011101110111001111111011111001001111110110101011001110111011100011110111111111111111111111111111111111111111111111111111111111 11111111111111111111011111111000001111111011100110011011111111011111011001111110110100011001111111011101101111011111111111111111111111111111111111111111111111111111111 11111111111111111111011111111000000011111000000111000111111111011111011001111111110110111001101111011101101111011111111111111111111111111111111111111111111111111111111 11111111111111111111011111111000111001110000110111000111111111000000011001111101110111111001101111011101110111011111111111111111111111111111111111111111111111111111111 11111111111111111111001111110010111100110111110111101111111111011111011011111101110111111001101111011110110111011111111111111111111111111111111111111111111111111111111 11111111111111111111001111110110111110110111110011101111111111011111011011111101100111111011100000001110110011011111111111111111111111111111111111111111111111111111111 11111111111111111111100111100110111110010111111011101111111111011111011001111001100111111011100111101110111011011111111111111111111111111111111111111111111111111111111 11111111111111111111110011001110111111000111111011101110111111011111011101111011100111111011101111101110111001001111111111111111111111111111111111111111111111111111111 11111111111111111111111000011110111111110111111011101110111111011111011100100111100111111001001111101110111101001111111111111111111111111111111111111111111111111111111 11111111111111111111111101111111111111111111111111111100111111111111111110001111111111111101001111100110111100011100111111111111111111111111111111111111111111111111111 11111111111111111111111111111111111111111111111111111101111111111111111111111111111111111111111111110110111110011111111111111111111111111111111111111111111111111111111 11111111111111111111111111111111111111111111111111111011111111111111111111111111111111111111111111111110111111111111111111111111111111111111111111111111111111111111111 11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111 11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111 11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111 11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111 11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111 11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111 11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111101111111111111111111111111111111111111111111111111111111111111111111111 11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111101111111111111111111111111111111111111111111111111111111111111111111111 11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110111111111111111111111111111111111111111111111111111111111111111111111 11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110111111111111111111111111111111111111111111111111111111111111111111111 11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110111111111111111111111111111111111111111111111111111111111111111111111 11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111011111111111111111111111111111111111111111111111111111111111111111111 11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111011111111111111111111111111111111111111111111111111111111111111111111 11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111011111111111111111111111111111111111111111111111111111111111111111111 11111111111111111111111111111111100111111111111111111111111111111111111111111111111111111111111111001111111111111111111111111111111111111111111111111111111111111111111 11111111111111111111111111111111100111111111101111111111111111111111111011111111111111111111111111001111111111111111111111111111111111111111111111111111111111111111111 11111111111111111111111111111111100111111011101111111111111111111110000000111111111111111111111111101111111111111111111111111111111111111111111111111111111111111111111 11111111111111111111111111111111100111111011101111110110011111111100111110111111111111111111110011101111111111111111111111111111111111111111111111111111111111111111111 11111111111111111111111111111111100111111011001111110111011111101101111111011111111111111111110001101111111111111111111111111111111111111111111111111111111111111111111 11111111111111111111111111111111110111111011001111110011011111101111111110011111111111111111111000000111111111111111111111111111111111111111111111111111111111111111111 11111111111111111111111111111111110111111011011111110011011111101111111110111111111111111111111001001111111111111111111111111111111111111111111111111111111111111111111 11111111111111111111111111111111110111110011011111111011011111101111111101111111111111111111111101111111111111111111111111111111111111111111111111111111111111111111111 11111111111111111111111111111111110000000011011111110111011111101111110001111111111111111111111101111111111111111111111111111111111111111111111111111111111111111111111 11111111111111111111111111111111110001110011011111110111000000001111100111111111111111111111111101111111111111111111111111111111111111111111111111111111111111111111111 11111111111111111111111111111111110111111011011111110111000000001111100111111111111111111111111110111111111111111111111111111111111111111111111111111111111111111111111 11111111111111111111111111111111110111111011101111110111011111101111100111111111111111111111111110111111111111111111111111111111111111111111111111111111111111111111111 11111111111111111111111111111111110111111011101111110111011111101111110111111111111111111111001110111111111111111111111111111111111111111111111111111111111111111111111 11111111111111111111111111111111110111111011101111101111011111101111111111111111111111111111000110111111111111111111111111111111111111111111111111111111111111111111111 11111111111111111111111111111111110011111001100110001111011111101111111111111111111111111111011010111111111111111111111111111111111111111111111111111111111111111111111 11111111111111111111111111111111110111111111111000111111011111101111111111111111111111111111011100111111111111111111111111111111111111111111111111111111111111111111111 11111111111111111111111111111111111111111111111111111111111111101111100011111111111111111111011110111111111111111111111111111111111111111111111111111111111111111111111 11111111111111111111111111111111111111111111111111111111111111101111100111111111111111111111011111111111111111111111111111111111111111111111111111111111111111111111111 11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111011111111111111111111111111111111111111111111111111111111111111111111111111 11111111111111111111111111111111111111111110111111111111111111111111111111111111111111111111011111111111111111111111111111111111111111111111111111111111111111111111111 11111111111111111111111111111111111111111100111111111111111111111111111111111111111111111111011111111111111111111111111111111111111111111111111111111111111111111111111 11111111111111111111111111111111111111111101111111111111111111111111111111111111111111111111011111111111111111111111111111111111111111111111111111111111111111111111111 11111111111111111111111111111111111111111001111111111111111111111111111111111111111111111111011111111111111111111111111111111111111111111111111111111111111111111111111 11111111111111111111111111111111111111111011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111 11111111111111111111111111111111111111111011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111 11111111111111111111111111111111111111110011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111 11111111111111111111111111111111111111110111111111111111111111111111111111111111111101100001100111111111111111111111111111111111111111111111111111111111111111111111111 11111111111111111111111111111111111111100111111111111111111111111111111111111111111000001100000000001100000000001111111111111111111001111110111111111111111111111111111 11111111111111111111111111111111111111111111111111111111111111111111111111111111111101111101011111111001111110110001101111111100000011111110111111011111111111111111111 11111111111111111111111111111111111111111111111111111111111111111111111111111111111101111101001111111101111101111101100000011101111111111111011111011001111111111110111 11111111111111111111111111111111111111111111111111111111111111111111111111111111111101111011101111111101111101111110101111101101111111111111001111010000011101111110111 11111111111111111111111111111111111111111111111111111111111111111111111111111111111101110011101111111101111101111111001111101101111111111111100110100111001101111110111 11111111111111111111111111111111111111111111111111111111111111111111111111111111111101000001100001111101111011111111001111001110111111111111110100101111100101111111011 11111111111111111111111111111111111111111111111111111111111111111111111111111111111101111110101111111101100011111111001110111110001111111111111001101111110101111111011 11111111111111111111111111111111111111111111111111111111111111111111111111111111111101111110101111111100001011111111010001111110000011111111111001101111110101111111011 11111111111111111111111111111111111111111111111111111111111111111111111111111111111101111110101111111101111011111111110001111110111111111111111011101111110101111111011 11111111111111111100000000111111111111111111111111111111111111111111111111111111111101111101101111111101111101111110110110011110111111111111111101101111110101111110111 11111111111111110011111111000111111111111111111111111111111111111111111111111111111101111101101111111101111101111110110111011110111111111111111101011111101101111110111 11111111111111100111111111111001111111111111111111111111111111111111111111111111111101111011100000001101111110111101110111101110111111111111111101001111101101111110111 11111111111111011111111111111110111111111111111111111111111111111111111111111111111100000111111000111101111111011001110111101110000000111111111101101111011110111110111 11111111111110011111111111111111011111111111111111111111111111111111111111111111111111111111111111111111111111100011111111101110001111111111111001100110111110011101111 11111111111110111111111111111111101111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111001111111100011111 11111111111100111111111111111111110111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111 11111111111101111111111111111111111011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111

continues…

… and interpreted such that 0 is black and 1 is white, will result in

okay-human-xkcd-371.png

Detail from: https://xkcd.com/371/

64 bits as a floating point number

0100000000001001001000011111101101010100010001000010110100011000

interpreted according to the IEEE Std 754 floating point standard is

\(3.141592653589793115997963468544185161590576171875\)

[Note that this is not the exact mathematical constant \(\pi\).]

This is the number you will get in Scala by using the build-in constant

scala.math.Pi

88 bits as a text

0100111101101011011000010111100100101100001000000110100001110101011011010110000101101110

Divided in 8-bit groups and interpreted according to Unicode (UTF-8) will give us:

Okay, human

Data format

Interpretation is all about the standard / format / convention

  • A sequence of bits (data) can be interpreted in many ways (although not all may make sense)
  • We need a convention of what the data represents
  • These are called formats, or
  • (in programming languages) referred to as the data types

For example, the bits

\(0100000000001001001000011111101101010100010001000010110100011000\),

interpreted as a Scala Double floating point value is \(3.141592653589793115997963468544185161590576171875\)

while interpreted as a Scala Long integer value it is \(4614256656552045848\).

Numerical and Textual data

  • Most programs involve at least numerical (representing numbers) and textual (representing text) data.
  • The basic data types in Scala can be divided into these two categories

    • numerical

          Byte, Short, Int, Long, Float, Double
      

      Represents signed (i.e. both positive and negative) integers

    • textual

         Char, String
      

      Represents single characters and strings

Lengths of basic value types in Scala

  • Scala is a hardware-independent language (It is designed to be used with many types of processors.)
  • The basic value types in Scala have the following fixed lengths in bits:
    • Byte : 8 bits
    • Short : 16 bits
    • Int : 32 bits
    • Long : 64 bits
    • Char : 16 bits

(Strings are sequences of Char)

Witnessing the bits, in Scala

  • Make use of the tellAbout… functions in the reading material
  • Prints binary representation of basic Scala datatypes and strings
  • Copy-n-paste definitions to the Scala REPL, or to code
  • Could be useful when debugging exercises
  • tellAboutByte
  • tellAboutShort
  • tellAboutInt
  • tellAboutLong
  • tellAboutChar
  • tellAboutString
  • tellAboutFloat
  • tellAboutDouble

Word, word length

  • Computers have build to process data in units which have a fixed number of bits (e.g. 8, 16, 32, 64, or 128 bits)
  • Units like this are called words
  • In a processor architecture the word length is the largest number of bits for which the processor can do computations with a single instruction
  • So 64 bit processor typically means that the word length is 64 bits

Bit indices in a Word

Example: 16 bit word

word-bit-indices.png

(Same as for decimal numbers, the least significant digit is the rightmost one.)

Hexadecimal numbers

  • Base 16 , digits 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F
  • Basic knowledge for a programmer
    • Easy to translate to and from binary representation
    • Compact (and unique) representation
  • Four bits make one hexadecimal digit
  • Words are generally multiples of 4 (e.g. 16,32,64)
Binary Hexadecimal
0000 0
0001 1
0010 2
0011 3
0100 4
0101 5
0110 6
0111 7
1000 8
1001 9
1010 A
1011 B
1100 C
1101 D
1110 E
1111 F

Hexadecimal numbers - example

bin-to-hex.png

Hexadecimal literals in Scala

  • Most programming languages that support hexadecimal literals prefix them by 0x.
  • For example: 0x62A9 for the hexadecimal \(62A9\)
scala> val a = 0x62A9
val a: Int = 25257
  • Note that a is and Int and that it is printed in the Scala REPL as a decimal number.
  • We can print it's hexadecimal representation (including the '0x' part) by a formatted string
scala> print("0x%X".format(a))
0x62A9

(The %X means "take the input to format and represent it as a hexadecimal integer")

If all data in a computer is represented using binary, then any operation on data types must be constructed from manipulation of bits

What operations are available?

Boolean operations on bits

boolean-ops.png

XOR stands for eXclusive OR

  • AND : "minimum"
  • OR : "maximum"
  • XOR : "sum, parity"
  • NOT : "toggle"

Forcing and toggling the value of a bit

boolean-force-toggle.png

Boolean operations on words

boolean-word-ops.png

Bit operations (by convention) work independently on each bit position of a word.

Forcing and toggling the value of a word

boolean-word-force-toggle.png

Shifting bits in a word

word-shift.png

Checking bit at specific position using Scala

scala> val x = 0x3A // 111010 in binary
val x: Int = 58

scala> (x >> 0) & 1 // value of bit at position 0
val res0: Int = 0

scala> (x >> 1) & 1 // value of bit at position 1
val res1: Int = 1

// Hmmmmm ....

scala> for i <- 0 until 6 do {
     print( (x >>> i)&1)
     } 
010111

Example: Creating a word with 1 at some position and 0 elsewhere

  • It is sometimes useful to create a word with zeroes everywhere except in some position j
  • This can be done by left shifting 1 the required number of steps
  • Mind the type (1 is 32 bits, 1L is 64 bits)

scala> val j = 3 // Index 3
val j: Int = 3
scala> val a = 1<<j  // Take a 1 and shift it left the required number of steps
val a: Int = 8

scala> tellAboutInt(a)
I am a 32-bit word that Scala views as having format 'Int' ...
... my bits are, in binary, (00000000000000000000000000001000)_2
... or equivalently, in hexadecimal, 0x00000008
... Scala prints me out as 8
... I represent the signed decimal integer 8
... I represent the unsigned decimal integer 8

scala> val j = 55 // Index 55
val j: Int = 55
scala> val c = 1L<<j // If you need 64 bits use a Long integer
val c: Long = 36028797018963968

scala> tellAboutLong(c)
I am a 64-bit word that Scala views as having format 'Long' ...
... my bits are, in binary, (0000000010000000000000000000000000000000000000000000000000000000)_2
... or equivalently, in hexadecimal, 0x0080000000000000
... Scala prints me out as 36028797018963968
... I represent the signed decimal integer 36028797018963968
... I represent the unsigned decimal integer 36028797018963968

Floating point numbers

scala> 0.3 - 0.1
val res10: Double = 0.19999999999999998

What is going on here?

Floating point standard

  • IEEE Std 754
  • Float = IEEE 754 'binary32'
  • Double = IEEE 754 'binary64'
  • Finite number of bits → Not all rational numbers can be represented
    • Moreover, which numbers that can be represented with a finite number of digits depends on the numerical base
  • IEEE 754-2008 “binary64” floating point number nearest to decimal value
    • \(0.3 \approx \left(1.0011001100110011001100110011001100110011001100110011\right)_2 \times 2^{-2}\) \(= 0.299999999999999988897769753748434595763683319091796875\)
    • \(0.1 \approx \left(1.1001100110011001100110011001100110011001100110011010\right)_2 \times 2^{-4}\) \(= 0.1000000000000000055511151231257827021181583404541015625\)

IEEE 754

  • Because the computer calculates with the binary representation \(0.3 - 0.1\) is actually \(0.299999999999999988897769753748434595763683319091796875\) \(- 0.1000000000000000055511151231257827021181583404541015625\)

It is good to be aware of the properties of floating point numbers when computing professionally with them –– make yourself familiar with the standard and remember that you are making computations with a fixed set of rational numbers, which become more sparse the larger their absolute values are.

(More in the reading material)

Exercises

Quiz
Convert between base 2 and base 10
Quiz
Solve boolean equations
Word Operations
Practice bit operations for words (how many bits with value 1 in a word, et c). Practice using bit-wise operators, shifts, et c.
Parity bits
Computing and checking the parity bit – basic error detection method
Base64 encoding
Encoding binary to text in base 64
(Challenge: Error corrcection)
One bit error correction, for example using Hamming code
(Challenge: Rational decompose)
Radix-point decomposition of a rational number

tellAbout… examples 1

tellAboutInt(25257)
I am a 32-bit word that Scala views as having format 'Int' ...
... my bits are, in binary, (00000000000000000110001010101001)_2
... or equivalently, in hexadecimal, 0x000062A9
... Scala prints me out as 25257
... I represent the signed decimal integer 25257
... I represent the unsigned decimal integer 25257
scala> tellAboutDouble(0.3)
I am a 64-bit word that Scala views as having format 'Double' ...
... my bits are, in binary, (0011111111010011001100110011001100110011001100110011001100110011)_2
... or equivalently, in hexadecimal, 0x3FD3333333333333
... Scala prints me out as 0.3
... indeed, my bits acquire meaning as specified
    in the binary interchange format 'binary64' in the
    IEEE Std 754-2008 IEEE Standard for Floating-Point Arithmetic
    http://dx.doi.org/10.1109%2FIEEESTD.2008.4610935
... this format is a bit-packed format with three components:
                            (0011111111010011001100110011001100110011001100110011001100110011)_2
    a) the sign
       (bit 63):             0
    b) the biased exponent
       (bits 62 to 52):       01111111101
    c) the trailing significand
       (bits 51 to 0):                   0011001100110011001100110011001100110011001100110011
... my biased exponent 1021 indicates that I am a _normalized_ number
    with a leading 1-digit in my significand and
    an unbiased exponent -2 = 1021 - 1023
... that is, in _binary radix point notation_, I am exactly
                                      (1.0011001100110011001100110011001100110011001100110011)_2 * 2^{-2}
... or what is the same in _decimal radix point notation_, I am exactly
    0.299999999999999988897769753748434595763683319091796875

Example 2

scala> tellAboutInt(-1)
I am a 32-bit word that Scala views as having format 'Int' ...
... my bits are, in binary, (11111111111111111111111111111111)_2
... or equivalently, in hexadecimal, 0xFFFFFFFF
... Scala prints me out as -1
... I represent the signed decimal integer -1
... I represent the unsigned decimal integer 4294967295

scala> tellAboutInt(-2)
I am a 32-bit word that Scala views as having format 'Int' ...
... my bits are, in binary, (11111111111111111111111111111110)_2
... or equivalently, in hexadecimal, 0xFFFFFFFE
... Scala prints me out as -2
... I represent the signed decimal integer -2
... I represent the unsigned decimal integer 4294967294