Ancient CS 61 Content Warning!!!!!1!!!
This is not the current version of the class.
This site was automatically translated from a wiki. The translation may have introduced mistakes (and the content might have been wrong to begin with).

Lecture 2 Notes: Representing Information

Administrative details

Homeworks due on Friday at 11:59:59pm<br\ Help from TF’s is not guaranteed after 9:00pm.<br\ Sections next week will cover git (version control software)

Representation of information

Computer = smoking hot cpu surrounded by an ocean of memory

Layer of abstraction between C and the machine

File:abstractionlayer.jpeg

A systems programmer programs for all of these layers

while -> property of C abstract machine<br\ INT_MIN: minimum representable value of type “int” -> property of target architecture

fork: starts a new program -> property of OS

Bits

A bit is either 0 or 1

Why are bits a good unit for computer design?

Memory is a cloud of bits

File:cloud.jpeg

In C:

Base 2 (Binary)

1111 1111 = 1x27 + 1x26 + … + 1x20 = 255

what is 1111 1111 + 1? with only 8 bits, the answer is 0. (we need 9 bits to represent 256).

1100 0000 = 128 + 64 = 192

Base 16 (Hexadecimal)

1111 1111 = 0xFF<br\ 1100 0000 = 0xC0

Digits in hex: <br\

hex    dec    binary
0      0      0000
1      1      0001
2      2      0010
3      3      0011
4      4      0100
5      5      0101
6      6      0110
7      7      0111
8      8      1000
9      9      1001
A      10     1010
B      11     1011
C      12     1100
D      13     1101
E      14     1110
F      15     1111

Addresses

To C, memory is a huge array of bytes:

unsigned char memory[];

Pointers and Arrays

Memory addresses can be treated exactly like integers.

unsigned char* x;                //this is a type representing an “address of a byte”
unsigned char* x = memory;    // x’s numeric value is set to 0
x = x + 1;                // x’s numeric value is 1
x = x - 1;                    // x’s numeric value is 0
unsigned char* y;
y = memory + 100;
if (x < y)                    // true
unsigned char bob;            // allocate space in memory for a char
x = &bob;                     // address of operator
File:bob.png

gcc -c x.c -o x.o

extern

objdump -s x.o

Information

Memory also contains code.<br\

Information is data + context.<br\ Steganography - hiding information in an image