Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 101 – Aug. 31 Interpreting binary  decimal √ Decimal  binary Shorthand ways of expressing binary –Octal –“Hex” Negative numbers.

Similar presentations


Presentation on theme: "CS 101 – Aug. 31 Interpreting binary  decimal √ Decimal  binary Shorthand ways of expressing binary –Octal –“Hex” Negative numbers."— Presentation transcript:

1 CS 101 – Aug. 31 Interpreting binary  decimal √ Decimal  binary Shorthand ways of expressing binary –Octal –“Hex” Negative numbers

2 Number of Possible Values 1 bit: 0 and 1 2 bits: 00, 01, 10, 11 3 bits: 000, 001, …? For a given number of bits, how many patterns?

3 decimal  binary You already know binary  decimal But given a decimal number like 45, what is binary form? Binary numbers are longer than decimal. –(Ex. 5 digit number may require 15 bits) My technique is the “binary store”

4 Binary store At the Binary Store, price is a power of 2: $1, $2, $4, $8, $16… If you had $45, what could you buy? 45 = 32 + 8 + 4 + 1 Write powers of 2: 2 5 + 2 3 + 2 2 + 2 0 Write binary number: 101101

5 Another example Let’s convert 61 to binary: Go to binary store with $61… 61 = 32 + 16 + 8 + 4 + 1 61 = 2 5 + 2 4 + 2 3 + 2 2 + 2 0 Finally: 111101

6 Octal Octal means base 8: each digit is a power of 8. Because 8 = 2 3, each octal digit corresponds to 3 bits 461 8 = 100 110 001 2 7325 8 = ?

7 Hexadecimal (“hex”) Base 16: each digit is a power of 16 Since 16 = 2 4, each hex digit corresponds to 4 bits. Hex also means we have 16 different digits. a = 10, b = 11, c = 12, d = 13, e = 14, f = 15

8 Hex examples 964 16 = 1001 0110 0100 2 d123 16 = 1101 0001 0010 0011 2 Now let’s go the other way: 111000 2 = ______ 16 10011111 2 = _______ 16

9 Decimal  octal, hex Often the best way to come up with octal or hex is to go thru binary first. Ex. What is 71 in octal? –Binary store gives: 71 = 64 + 4 + 2 + 1 –Binary number is 1000111 –Grouped as octal: 001 000 111 2 = 107 8 We can check answer.

10 Why couldn’t the computer scientist tell the difference between Halloween (Oct 31) and Christmas (Dec 25) ?

11 Negatives? We can used a “signed” representation. We want half the rep’ns to be negative. Ex. 5 bits  32 numbers. –16 numbers are negative –Thus, range is –16 to +15. For n bits: range is –2 n–1 to 2 n – 1 – 1

12 How to represent negatives In ordinary (unsigned) binary, this was impossible! In signed: 3 steps to represent –x: 1.Find rep’n of +x. 2.Invert the bits. 3.Add 1. Try some examples.


Download ppt "CS 101 – Aug. 31 Interpreting binary  decimal √ Decimal  binary Shorthand ways of expressing binary –Octal –“Hex” Negative numbers."

Similar presentations


Ads by Google