Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 111 – Sept. 1 Intro to data representation Binary numbers –Convert binary  decimal –Convert decimal  binary Text –ASCII and Unicode Commitment: –For.

Similar presentations


Presentation on theme: "CS 111 – Sept. 1 Intro to data representation Binary numbers –Convert binary  decimal –Convert decimal  binary Text –ASCII and Unicode Commitment: –For."— Presentation transcript:

1 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

2 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, 001110 and 100011: 32 *16 *8 *4 *2 *1 *Value 00111026 10001135

3 Powers of 2 2 0 = 1 2 1 = 2 2 2 = 4 2 3 = 8 2 4 = 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?

4 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 = 32 + 8 + 4 + 1 32 *16 *8 *4 *2 *1 * 101101

5 Another example Convert 61 to binary: Go to binary store with $61… 61 = 32 + 16 + 8 + 4 + 1 Another way to write this is: 61 = 2 5 + 2 4 + 2 3 + 2 2 + 2 0 Our binary answer is 111101.

6 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: 01011110 2 = 5e in hex. –Try this one: 111000 2 = ______ in hex. –Try this one: a4c in hex = ________ in binary.

7 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”

8 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.


Download ppt "CS 111 – Sept. 1 Intro to data representation Binary numbers –Convert binary  decimal –Convert decimal  binary Text –ASCII and Unicode Commitment: –For."

Similar presentations


Ads by Google