Binary, Octal and Hexidecimal numbers - PowerPoint PPT Presentation

1 / 50
About This Presentation
Title:

Binary, Octal and Hexidecimal numbers

Description:

... is base 10 called decimal. You can have other systems with a different base (also called radix) ... In Elementary school, students are asked to write ... – PowerPoint PPT presentation

Number of Views:348
Avg rating:3.0/5.0
Slides: 51
Provided by: sfu4
Category:

less

Transcript and Presenter's Notes

Title: Binary, Octal and Hexidecimal numbers


1
Binary, Octal and Hexidecimal numbers
  • Mr. Simon
  • Lowell High School
  • San Francisco, CA

2
Numeral Systems
  • The common system of numerals is base 10 called
    decimal
  • You can have other systems with a different base
    (also called radix)
  • In computers, the common systems are
  • Base 2 called binary
  • Base 8 called octal
  • Base 16 called hexidecimal

3
Place value and expanded notation
  • In Elementary school, students are asked to write
    numbers in expanded notation
  • 1,235 1000 200 30 5
  • 1 (103) 2 (102) 3 (101) 5 (100)
  • In a decimal number each digit has a place value
    that is a power of 10

4
Binary place values are powers of 2
  • In Binary, each digit has a place value that is a
    power of 2
  • 1011

5
Converting Binary to Decimal
  • To convert binary to decimal, just write the
    number out in expanded notation
  • 1011 1 (23) 0 (22) 1 (21) 1 (20)

6
Converting Binary to Decimal
  • To convert binary to decimal, just write the
    number out in expanded notation
  • 1011 1 (23) 0 (22) 1 (21) 1 (20)
  • 18 04 12 11

7
Converting Binary to Decimal
  • To convert binary to decimal, just write the
    number out in expanded notation
  • 1011 1 (23) 0 (22) 1 (21) 1 (20)
  • 18 04 12 11
  • 8 0 2 1

8
Converting Binary to Decimal
  • To convert binary to decimal, just write the
    number out in expanded notation
  • 1011 1 (23) 0 (22) 1 (21) 1 (20)
  • 18 04 12 11
  • 8 0 2 1
  • 11

9
Powers of 8
  • 20 1
  • 21 2
  • 22 4
  • 23 8
  • 24 16
  • 25 32
  • 26 64
  • 27 128

10
Binary numbers often comein groups of eight
called octets
  • If all 8 bits are 0s 00000000 then the value of
    the octet is 0.
  • If all 8 bits are 1s, 11111111 then the value of
    the octet is 255 (1286432168421).
  • If the 8 bits are mixed, such as 10101000, add
    the place values of the 1 bits 128 32 8 168

11
Binary Game!
12
Octal Numbers
  • Octal is base 8
  • Binary numbers are long and unwieldy
  • Octal makes it easier to represent binary numbers
    than decimal 3 binary digits map to one Octal
    digit
  • So the same number in binary has three times as
    many digits as it would in Octal
  • Octal is used in Linux, for instance to set user
    permissions using the chmod command

13
Place Value
  • In base 8, each place value is a power of 8
  • 1,245 (base 8) 1x83 2x82 4x81 5x80

14
Converting to base 10
  • To convert a number from another base to base 10
  • Just write out the number in expanded notation,
    and evaluate it
  • 1,245 (base 8) 1x83 2x82 4x81 5x80

15
Converting to base 10
  • Just write out the number in expanded notation,
    and evaluate it
  • 1,245 (base 8) 1x83 2x82 4x81 5x80
  • 512 128 32 40

16
1,245 (base 8) 712 (base 10)
  • Just write out the number in expanded notation,
    and evaluate it
  • 1,245 (base 8) 1x83 2x82 4x81 5x80
  • 512 128 32 40
  • 712 (base 10)

17
Converting from base 10
  • Converting from base 10 to another base is the
    opposite
  • First, figure out what the highest place value is
  • Then, work from the highest place value to the
    lowest

18
197 (base 10) ?? (base 8)
19
197 (base 10) ?? (base 8)
  • What's the largest power of 8 that will go into
    197?
  • 80 1
  • 81 8
  • 82 64
  • 83 512

20
19710 ? x 82 ? x 81 ? x 80
  • Since 64 is the largest power of 8 that will fit,
    we know that the number will have these three
    place values
  • 80 1
  • 81 8
  • 82 64
  • 83 512

21
19710 ? x 82 ? x 81 ? x 80
  • How many times will 64 go into 197?
  • 64 x 1 64
  • 64 x 2 128
  • 64 x 3 192

22
19710 3 x 82 ? x 81 ? x 80
  • Now how much room do we have for the next power
    of 8?
  • 197 192 5
  • 81 x ?

23
19710 3 x 82 0 x 81 ? x 80
  • Now how much room do we have for the next power
    of 8?
  • 197 192 5
  • 81 x 0 0
  • 81 x 1 8

24
19710 3 x 82 0 ? x 80
  • Now how much room do we have for the next power
    of 8?
  • 197 192 - 0 5
  • 80 x 4 4
  • 80 x 5 5
  • 80 x 6 6

25
19710 3 x 82 0 x 81 5 x 80
  • So, 197(base 10) 305(base 8)

26
Luckily, you dont usually convert back and forth
from decimal to octal
  • Octal converts easily back and forth from binary
  • One Octal digit maps to three Binary Digits
  • So, 101001 is

27
Luckily, you dont usually convert back and forth
from decimal to octal
  • Octal converts easily back and forth from binary
  • One Octal digit maps to three Binary Digits
  • So, 101 001 is

28
Luckily, you dont usually convert back and forth
from decimal to octal
  • Octal converts easily back and forth from binary
  • One Octal digit maps to three Binary Digits
  • So, 101 001 is
  • 5 1

29
Luckily, you dont usually convert back and forth
from decimal to octal
  • Octal converts easily back and forth from binary
  • One Octal digit maps to three Binary Digits
  • So, 1010012 is 518
  • Its that easy!

30
Convert 4728 to binary
  • Again, each Octal digit maps to three Binary
    digits

31
Convert 4728 to binary
  • Again, each Octal digit maps to three Binary
    digits
  • So 472 is

32
Convert 4728 to binary
  • Again, each Octal digit maps to three Binary
    digits
  • So 4 7 2 is

33
Convert 4728 to binary
  • Again, each Octal digit maps to three Binary
    digits
  • So 4 7 2 is
  • 100 111 010

34
Convert 4728 to binary
  • Again, each Octal digit maps to three Binary
    digits
  • So 4728 is 1001110102
  • Easy!

35
In Class
  • Convert each octal value to binary, and each
    binary value to octal
  • 63
  • 70
  • 100100101
  • 001101101

36
Hexadecimal Numbers
  • hex for short
  • Hexadecimal is base 16
  • It uses sixteen distinct symbols, the symbols 09
    to represent values zero to nine, and A, B, C, D,
    E, F to represent values ten to fifteen

37
Mac addresses are usually in hex
  • 00-13-D3-A2-8F
  • Some IP addresses (IPv6) are also written in hex
  • Encryption keys in wireless routers can be in hex
  • You can usually spot hex because it has only the
    letters A-F

38
Converting Hex to Decimal
  • In a hex number, each place value is a power of
    16
  • 13FA

39
Converting Hex to Decimal
  • In a hex number, each place value is a power of
    16
  • 13FA 1 (163)3 (162)15 (161)10 (160)

40
Converting Hex to Decimal
  • In a hex number, each place value is a power of
    16
  • 13FA 1 (163)3 (162)15 (161)10 (160)
  • 4096 768 240 10

41
Converting Hex to Decimal
  • In a hex number, each place value is a power of
    16
  • 13FA 1 (163)3 (162)15 (161)10 (160)
  • 4096 768 240 10
  • 5114

42
If you use a table, converting back and forth
from hex to binary is easy
  • To convert hexadecimal F8 to binary, write down
    the binary for F first, then the binary for 8.
  • F 8
  • 1111 1000
  • So, the answer is 11111000
  • Thats all there is to it!

43
Converting Binary to Hex
  • Converting Binary to Hex is just as easy
  • 01011110101101010010
  • 0101 1110 1011 0101 0010
  • 5 E B 5 2
  • 5EB52

44
In Class
  • Convert each hex value to binary, and each binary
    value to hex
  • E1
  • 15
  • 10010010
  • 00110110

45
Sometimes binary and hexcome up in Java
  • The getRGB() function returns a single int that
    has all three values
  • //get RGB values at mouseX and mouseY
  • int c image.getRGB(mouseX, mouseY)
  • //use bitwise logical operations
  • int red (c 0x00ff0000) gtgt 16
  • int green (c 0x0000ff00) gtgt 8
  • int blue c 0x000000ff
  • So let's say we clicked on a magenta area. . .

46
Sometimes binary and hexcome up in Java
  • getRGB() will return 0x00FF00FF
  • which in binary is
  • 00000000 11111111 00000000 11111111
  • The octets are opacity, red, green and blue

47
The bitwise
  • int red (c 0x00ff0000) gtgt 16
  • The single is the bitwise logical AND
  • We're looking for the bits that are 1 in both
    numbers
  • 00000000 11111111 00000000 11111111
  • 00000000 11111111 00000000 00000000

48
The bitwise
  • int red (c 0x00ff0000) gtgt 16
  • So this expression evaluates to
  • 00000000 11111111 00000000 11111111
  • 00000000 11111111 00000000 00000000
  • 00000000 11111111 00000000 00000000

49
gtgt bit-shift operator
  • int red (c 0x00ff0000) gtgt 16
  • This means shift to the right 16 places
  • 00000000 11111111 00000000 00000000

50
gtgt bit-shift operator
  • int red (c 0x00ff0000) gtgt 16
  • This means shift to the right 16 places
  • 00000000 11111111 00000000 00000000
  • which means that red is assigned
  • 00000000 00000000 00000000 11111111
  • which is 255 in decimal
Write a Comment
User Comments (0)
About PowerShow.com