CS 111 – Sept. 1 Intro to data representation Binary numbers –Convert binary decimal –Convert decimal binary Text –ASCII and Unicode Commitment: –For lab: Be sure you understand number conversions –For Friday: Please finish reading sections 1.4 and 1.5
Numbers in binary Place value system just like decimal –We understand 278 = (2 * 100) + (7 * 10) + (8 * 1) In a binary number: –Each digit is either a 0 or 1 –Digits are multiplied by powers of 2, not powers of 10. For example, and : 32 *16 *8 *4 *2 *1 *Value
Powers of = = = = = 16 … 2 10 ~ 1 thousand 2 20 ~ 1 million 2 30 ~ 1 billion Let’s say we have 4 bits. –What is the lowest # ? –What is the highest # ? What if we had 5 bits? Is there a pattern?
Decimal binary One thing to note is that binary numbers are “longer” than decimal. –A 5-digit decimal number may turn out to be 15 bits long. My technique is the “binary store” –All merchandise is priced $1, $2, $4, $8, $16, … –You enter store with some money, say $45. –Goal is to always buy most expensive gift possible. –So, 45 = *16 *8 *4 *2 *1 *
Another example Convert 61 to binary: Go to binary store with $61… 61 = Another way to write this is: 61 = Our binary answer is
Numbers in a byte A byte is 8 bits So, how big can an 8-bit binary number be? Hexidecimal shorthand –8/4 = 2 hexidecimal digits per byte –What do the letters ‘a’ – ‘f’ mean? a = 10, b = 11, c = 12, d = 13, e = 14, f = 15 –Example: = 5e in hex. –Try this one: = ______ in hex. –Try this one: a4c in hex = ________ in binary.
Text Fundamental unit is the character. Each character of a text document is given a numerical code. ASCII code –Contiguous (make it easy to alphabetize) –Case sensitive –One byte per character ASCII table (p. 597) –‘A’ = 65‘a’ = 97‘0’ = 48 –Try encoding the word: “Dog”
Unicode To support foreign alphabet and misc. symbols. Extension of ASCII 16 bits per character, rather than 8 unicode.org has code charts Codes are given in hex.