CS208 Introduction to Computer Systems Wednesday, 17 January 2024 + Queues questions + Questions we want to answer Note that "= ?" in these examples means "represents what integer?" 0101 = ? if it's just a binary number 0101 = ? if it's a 4-bit 2's complement representation of a number 1100 = ? binary 1100 = ? 4-bit 2's comp 00011001 = ? binary 00011001 = ? 8-bit 2's comp 0x19 = ? hexadecimal 0x19 = ? 8-bit 2's comp 11111010 = ? binary 11111010 = ? 8-bit 2's comp 0xFA = ? hexadecimal 0xFA = ? 8-bit 2's comp 0xFFFA = ? 16-bit 2's comp 0xFFFFFFFA = ? 32-bit 2's comp + Notes - Integers are integers. There are an infinite number of them. They're our old friends: ...-3, -2, -1, 0, 1, 2, 3,... - We have a bunch of ways of writing integers down on paper (decimal, binary, octal, hexadecimal); for negative integers, we stick a minus sign in front - Those ways of writing integers I just mentioned? They apply to any integer, no matter how big, limited only by our supply of paper and ink or stone and chisel etc. - Those aren't the only ways of writing integers. (Could you use DNA-editing techniques to write integers in molecule form? Yes!) - If we say "all we have is a bunch of two-state devices and we want to write integers using those devices", we can use ordinary binary to handle positive integers, but we're gonna need a trick to help us represent negative integers. - Several common tricks exist (https://en.wikipedia.org/wiki/Signed_number_representations) "signed magnitude" "excess-K" (also know as "offset-K", "bias-K") "one's complement" "two's complement" <---- BY FAR THE MOST COMMONLY USED ---- + Summary of techniques - Given a hex representation of a 32-bit bit pattern, write it out as bits - Given a hex representation of a 32-bit bit pattern, determine what integer the bits represent if they're interpreted using the 32-bit two's complement scheme - Given a hex representation of a 32-bit bit pattern, determine which ASCII characters those bits represent - Given a 32-bit bit pattern and the integer N the bits represent using the two's complement scheme, what bit pattern represents the negation -N? + Look at it in C - sizeof(char), sizeof(short), sizeof(int), sizeof(long) - experiments with int variables and printf - experiments with char variables and printf (WTH?!!)