Information Representation
Reading and References Reading - Computer Organization and Design, Patterson and Hennessy Chapter 2, sec. 2.4, 2.9 (first page only for now) 2
Review: A Computer is … main memory I/O bus processor/memory bus processor hardvideo /opticalserialnetwork diskcameradriveportsinterface 3
Processor & Memory For now we focus on the processor & memory Processor operation - Fetch next instruction from memory - Fetch instruction operands (data) from memory - Perform operation (add, subtract, test, …) - Store result (if any) in memory - Repeat Billions of times a second Memory holds all instructions and data What is memory made of? 4
Bits All memories are composed of (billions of) bits Abitis: - high or low voltage - 0or1 - true or false - yes or no - on or off It’s all how you interpret it But to store anything complicated we use a bunch of bits to make up a number, character, instruction, … 5
Computer Memory All memories are organized by grouping sets of bits into individual memory cells Each cell has an address and its contents Standard organization now: 1 cell = 8 bits = 1 byte A single byte can hold - A small integer (0-255 or ) - A single character (‘a’, ‘A’, ‘?’, ‘#’, ‘ ’, …) – A boolean value ( , ) 6
Memory Organization Memory is a linear array of bytes; each byte has an address (or location) - not the same as its contents Groups of bytes can be treated as a single unit 7
Some common storage units unit# bits byte8 half-word 16 word 32 double word 64 Terminology varies: this is how MIPS does it; the Intel x86 calls 16 bits a word & 32 bits a double-word 8
Alignment An object in memory is “aligned” when its address is a multiple of its size Byte: always aligned Halfword: address is multiple of 2 Word: address is multiple of 4 Double word: address is multiple of 8 Alignment simplifies load/store hardware - And is required by MIPS, but not x86 9
Binary Arithmetic Just as we do with decimal numbers, we can treat a collection of bits as a multi-digit number in base 2 Example: = 1 × × × × 2 0 = ____________ You try it: = ____________ ? 10
Binary, Hex, and Decimal It’s unwieldy to work with long strings of binary digits, so we group them in chunks of 4 and treat each chunk as a digit in base 16 Hex digits: -0 = 0000,1 = 0001,2 = 0010,3 = 0011 – 4 = 0100,5 = 0101,6 = 0110,7 = 0111 – 8 = 1000,9 = 1001, __ = 1010, __ = 1011 – _ = 1100, __ = 1101, __ = 1110, __ = 1111 Usual notation for hex integer in C, Java, …: 0x1c4 11
Hex Numbers What is 0x2a5 in decimal? - 0x2a5 = 2 × a × × 16 0 = ________________________________ What about 0xbad? _____________________ Be sure you realize that 0x11 ≠ ≠
More problems What is in hex? ______________________________________ What is 0xbeef in binary? - (Hint: there’s a trick) _______________________________________ 13
Binary, Hex, and Decimal Binary 2 Hex x x xA xF x x1F x7F xFF
Binary, Hex, and Decimal Hex 16 Decimal x x xA xF x x1F x7F xFF255 15
Binary, Hex, and Decimal Binary 2 Decimal A F F F F
Unsigned binary numbers Each bit represents a power of 2 For unsigned numbers in a fixed width n-bit field: - 2 n distinct values - the minimum value is 0 - the maximum value is 2 n-1, where n is the number of bits in the field Fixed field widths determine many limits - 5bits=32possiblevalues(2 5 = 32) - 10 bits = 1024 possible values (2 10 = 1024) 17
Signed Numbers For unsigned numbers, - each bit position represents a power of 2 - range of values is 0 to 2 n -1 How can we indicate negative values? - two states: positive or negative - a binary bit indicates one of two states: 0 or 1 ⇒ use one bit for the sign bit 18
Where is the sign bit? Could use an additional bit to indicate sign - each value would require 33 bits - would really foul up the hardware design Could use any bit in the 32-bit word - any bit but the left-most (high order) would complicate the hardware tremendously ∴ The high order bit (left-most) is the sign bit - remaining bits indicate the value 19
Format of 32-bit signed integer sign bitnumeric value (1 bit)(31 bits) Bit 31 is the sign bit - 0 for positive numbers, 1 for negative numbers - aka most significant bit (msb), high order bit 20
Example: 4-bit signed numbers Hex Bin F 1111 E 1110 D 1101 C 1100 B 1011 A Unsigned Signed Decimal sign bit (1 bit) numeric value (3 bits)
Two’s complement notation Note special arrangement of negative values One zero value, one extra negative value The representation is exactly what you get by doing a subtraction DecimalBinary
Why “two’s” complement? In an n-bit binary word, negative x is represented by the value of 2 n -x. The radix (or base) is 2. 4-bit example 2 4 = 16. What is the representation of -6? DecimalBinary
Negating a number Given x, how do we represent negative x? negative(x) = 2 n -x and x+complement(x) = 2 n -1 sonegative(x) = 2 n -x = complement(x)+1 The easy shortcut - write down the value in binary - complement all the bits - add 1 24
Example: the negation shortcut decimal 6 = 0110 = +6 complement = 1001 add 1 = 1010 = -6 decimal -6 = 1010 = -6 complement = 0101 add 1 = 0110 = +6 25
Why 2’s complement? (Again) The key advantage is that we can add two numbers together without paying any attention to the sign and we get the properly signed result 26
What About Non-Numeric Data? Everything is bits So assign (arbitrarily) specific bit patterns (numbers) to represent different characters Two most common codes - ASCII - original 7-bit code, early 1960’s How many possible characters? - Unicode to 32-bit code to represent enough different characters to encode all currently used alphabets; started in the late 1980s 27
ASCII 33!49165A81Q97a113q 34 ” 50266B82R98b114r 35#51367C83S99c115s 36$52468D84T100d116t 37%53569E85U101e117u 38&54670F86V102f118v 39 ’ 55771G87W103g119w 40(56872H88X104h120x 41)57973I89Y105I121y 42*58:74J90Z106j122z 43+59;75K91[107k123{ 44,60<76L92\108l124| 45-61=77M93]109m125} 4662>78N94^110n126~ 47/63?79O95111o127del 28
But wait, there’s more! We still haven’t looked at - Floating-point numbers (scientific notation) - Strings/arrays - Records/structs/objects - Colors and images - Sounds We’ll see some of this, but it’s all encoded as numbers (i.e., collections of bits) But next we need to look at how the computer processes these things - instructions 29