Introduction to Computer Systems
Everything Is A Number

# Everything Is A Number

## Electronics

- Circuits are read as high or low (high = 1, low = 0). Ths is because the circuits aren’t consistent - it moves up and down, not always the same for 1.

## More Than Two Values

- Binary = 0 and 1 only. How do we get more values?
- How do humans write the value for one million? do we have a special symbol? How do we invent a number larger than our larger number
- using 10 digits (1, 2, … , 9, 10) we can represent any number
- We use powers of tens

- Same for Binary:
- In base 2 instead of base 10
- 100 = 4 in binary
- 100
_{2}= (1 x 2^{2}) + (0 x 2^{1}) + (0 x 2^{0}) = 4

- 100
- 10011 = 19 in Binary

## Fractional Values

- Comining bits gets natural numbers. How do we get fractional values?
- How do we keep track of where numerater begins and denominator ends?

## Characters As Numbers

- How do we store letters as numbers
- Convert letter to number? (A=0, B=1, etc)
- Using THIS, 5 bits needed to store all letters
- Need a common mapping for letter translation
- That’s what ASCII is - American Standard Code for Information Interchange
- Uses 7 bits to store all 128 characters

## Text As Numbers

- How do we store words?
- Each culture does it differently

- Computer equivelent to doing this is Unicode - has 128,000 characters. Global standard for all computer characters.
- Computers make words (in C) using an array of characters

## Images As Numbers

- Divide pixels into 3 8-Bit numbers - Red, Green, and Blue
- 0 = Black
- 255 = White
- Why RGB? - These colors of light can blend to make all colors

## Audio As Numbers

- We need to discretize the continuous anolog sound by sampling it at regular intervals
- If we sample it frequently enough, our ears cannot tell this difference between this and continuous audio
- Just like how movies are not continuous - they’re pictures placed so closely together that is looks continuous

- If we use discrete values, our ears cannot distinguish between them
- Not just 0 or 1
- Lots of values also allows us to play a sound that is as close as possible to the exact value of the sound

## Video As Numbers

- Display as an array, synced with specific times in audio

## Anything Can Be A Number

- Math Equations - Mathematica
- Odor - Smell-O-Vision
- Money - Bitcoin

## Hexedecimal

- Group a series of 4 bits together represent them with a character
- 10110101001011010001101011001010 = B52D1ACA (in C - 0xB52D1ACA)

## Fixed Data Sizes

- We need to know when a value starts and stops, so on a cimputer we use fixed data sizes.
- C doesn’t specify sizes for values, so the same types are different sizes on different computer

## Byte Ordering

**Big Endian**- Most significant bit (but that changes the value the most) goes on the left, the least significant bit goes on the left.**Little Endian**- Reverse of Big Endian

## Bitwise Operators

C provides 6 operators that deal with individual bits of a variable

`&`

– Bitwise AND –`0011 & 1010 == 0010`

`|`

– Bitwise OR –`0011 | 1010 == 1011`

`^`

– Bitwise XOR –`0011 ^ 1010 == 1001`

`<<`

– Left Shift –`1010 0011 << 3 = 0001 1000`

`>>`

– Right Shift –`1010 0011 >> 3 = 0001 0100`

[signed value:`1111 0100`

]`~`

– Bitwise Complement –`~ 1010 0011 = 0101 1100`