Agenda - PowerPoint PPT Presentation

1 / 77
About This Presentation
Title:

Agenda

Description:

Reading left to right, multiply placeholder (1 or 0) by the ... Calculate decimal equivalent (in placeholders in powers of 2) Convert to Hexadecimal number ... – PowerPoint PPT presentation

Number of Views:37
Avg rating:3.0/5.0
Slides: 78
Provided by: murra83
Category:

less

Transcript and Presenter's Notes

Title: Agenda


1
Agenda
  • Data Representation
  • Purpose
  • Numbering Systems
  • Decimal
  • Binary
  • Conversions
  • Decimal to Binary
  • Binary to Decimal

2
Agenda
  • How Computers Store Data
  • Numbering Systems
  • Octal
  • Hexadecimal
  • Conversions
  • Decimal to Binary
  • Binary to Decimal

3
Data Representation Game
  • Groups
  • Number Systems
  • Roman Numerals,
  • Chinese,
  • Decimal,
  • Binary,
  • Blocks,
  • Hexadecimal,
  • Octal

4
How Computers Store Data
  • Computers are electronic devices that store data
    in a series of switches (circuits) which are
    either on or off.
  • The digit 1 indicates that the switch is ON
  • The digit 0 indicates that the switch is OFF
  • Because there are two possible ways in which to
    represent this type of digit, we call this system
    as a binary number system

5
How Computers Store Data
  • In order to have the computer store various
    alphabetical (upper and lower case) characters as
    well as numbers and special characters, one
    binary digit is not sufficient.
  • Computers will use a series of binary digits
    (referred as bits) to represent a character (byte)

6
How Computers Store Data
  • How to determine total number of character
    possibilities for a binary numbering system
  • 2n
  • Where n represents the number of binary digits
    or bits

7
Various Encoding Schemes
8
Various Encoding Schemes
9
Why Study Numbering Systems?
  • Humans are most comfortable with the decimal
    Numbering System (digits containing 10
    possibilities).
  • Unfortunately, humans are not comfortable (or
    efficient) working with binary numbers (as stored
    in computers).
  • To compromise, humans may need to learn binary,
    octal hexadecimal numbering systems

10
Purpose of Data Representation
  • It is important to understand the various methods
    that computers interpret characters and numbers.
  • Programmers need to know, from time-to-time how
    to translate or interpret data represented by
    computers

11
Numbering Systems
  • Decimal (Base 10)
  • numbering system for humans
  • Binary (Base 2)
  • numbering system for computers
  • Octal(Base 8)/ Hexadecimal(Base16)
  • Shorthand method of representing binary numbers

12
Decimal Numbers (Base 10)
  • The decimal system is a positional system. Each
    digit represents a quantity via its position in
    the number. This system is best understood by
    humans.
  • The numbers are represented as sums of the powers
    of ten (hence decimal system)

13
Decimal Numbers (Base 10)
  • Look at number 3572 as sums of powers of 10
  • 3x103 3x1000 3000
  • 5x102 5x100 500
  • 7x101 7x10 70
  • 2x100 2x1 2
  • 3,572

14
Decimal Numbers (Base 10)
  • When referring to the number as a decimal system
    (base 10), the number is displayed as normal
  • eg. 3,572

15
Binary Numbers (Base 2)
  • The binary system is a system based on two
    numbers
  • 0 and 1
  • The numbers are represented as sums of the powers
    of two
  • (i.e. Combinations of 0 or 1)

16
Binary Numbers (Base 2)
  • Lets take the binary number 110101. What does
    this binary number represent as a number that
    humans would understand?
  • We could to convert binary number to a decimal
    number

17
Rules to Convert Binary Number to Decimal Number
  • Steps
  • Reading left to right, multiply placeholder (1 or
    0) by the corresponding power of 2

18
Convert Binary to Decimal
  • 110101
  • 1x25 1 x 32 32
  • 1x24 1 x 16 16
  • 0x23 0 x 8 0
  • 1x22 1 x 4 4
  • 0x21 0 x 2 0
  • 1x20 1 x 1 1
  • Decimal 53

19
Binary Numbers (Base 2)
  • When referring to the number as a binary (base
    2), the number is displayed with the subscript 2
    to not confuse number with decimal
  • eg.
  • 10 (Decimal)
  • 102 (Binary) 1x21 0x20 2

20
Definitions
Quotient
Divisor
Dividend
- Divisor x Quotient
Remainder
21
Converting Decimal to BinaryMethod 1
  • Steps
  • 1. Divide the number by 2 and save the
  • quotient for the next step. Write the
  • remainder on the side
  • 2. If the quotient in step 1 is 0, stop
  • 3. If the quotient in step 1 is not 0, repeat
  • step 1, using the quotient as the new number
  • Obtain the answer by reading the remainders in
    the inverse order in which they are produced

22
How to convert Decimal to BinaryMethod 2
  • Divisor is 2 (binary is base 2)
  • Dividend is the DECIMAL number to be converted
  • Remainder is THE CURRENT DIGIT
  • Quotient is the dividend for the next largest
    digit.

23
Converting Decimal to BinaryMethod 1
  • Convert 25 to binary
  • Calculation Quotient Remainder
  • 25 / 2 12 1
  • 12 / 2 6 0
  • 6 / 2 3 0
  • 3 / 2 1 1
  • 1 / 2 0 1
  • 0 / 2

24
Converting Decimal to BinaryMethod 1
  • Convert 25 to binary
  • Calculation Quotient Remainder
  • 25 / 2 12 1
  • 12 / 2 6 0
  • 6 / 2 3 0
  • 3 / 2 1 1
  • 1 / 2 0 1
  • (Reading up) 25 110012

Remember Read upwards!!
25
How to convert Decimal to BinaryMethod 2
  • Divisor is 2
  • Dividend is 25
  • Quotient is 12
  • Remainder is 1
  • Therefore the rightmost digit is 1

26
How to convert Decimal to BinaryMethod 2
12
25
2
- 24
1
27
How to convert Decimal to BinaryMethod 2
  • A second division takes place
  • New Dividend is 12 (The quotient from previous
    slide - step 1)

28
How to convert Decimal to BinaryMethod 2
12
12
25
2
2
- 24
1
29
How to convert Decimal to BinaryMethod 2
  • Divisor is 2
  • New Dividend is 12 (The quotient from step 1)
  • Quotient is 6
  • Remainder is 0
  • Therefore the next digit is 0

30
How to convert Decimal to BinaryMethod 2
6
12
25
2
12
2
- 24
- 12
1
0
31
How to convert Decimal to BinaryMethod 2
3
12
6
6
25
2
2
12
- 24
- 12
- 6
1
0
0
32
How to convert Decimal to BinaryMethod 2
1
12
3
6
3
6
25
12
2
- 6
- 24
- 12
- 2
1
0
0
1
33
How to convert Decimal to BinaryMethod 2
0
12
3
1
6
3 - 2
1
6
25
12
2
- 6
- 24
- 12
- 0
1
0
1
0
1
34
How to convert Decimal to BinaryMethod 2
0
12
3
1
6
3 - 2
1
6
25
12
2
- 6
- 0
- 24
- 12
1
0
1
0
1
Final value of Decimal 25 in Binary is 110012
35
How to convert Decimal to BinaryMethod 2
  • Check
  • 110012 1 x 16 1 x 8 1
  • 16 8 1
  • 25

NOTE Method 2 can be used instead of Method 1
in all the examples which follow.
36
Octal Numbers (Base 8)
  • The octal system is a system based on eight
    numbers
  • 0, 1, 2, 3, 4, 5, 6, 7
  • The numbers are represented as sums of the powers
    of eight

37
Octal to Decimal Conversion
  • Lets take the octal number 7268. What does this
    octal number represent as a number that humans
    would understand?
  • We could convert octal number to a decimal number

38
Rules to Convert Octal Number to Decimal Number
  • Steps
  • Reading left to right, multiply placeholder (0
    through 7) by the corresponding power of 8

39
Convert Octal to Decimal
  • 7268
  • 7x82 7 x 64 448
  • 2x81 2 x 8 16
  • 6x80 6 x 1 6
  • Decimal 470

40
Convert Decimal to Octal
  • We convert from decimal to octal by a procedure
    similar to converting decimal to binary
  • Instead of successively dividing by 2, we
    successively divide by 8

41
Convert Decimal to Octal
  • Steps
  • 1. Divide the number by 8 and save the
  • quotient for the next step. Write the
  • remainder on the side
  • 2. If the quotient in step 1 is 0, stop
  • 3. If the quotient in step 1 is not 0, repeat
  • step 1, using the quotient as the new number
  • Obtain the answer by reading the remainders in
    the inverse order in which they are produced

42
Converting Decimal to Octal
  • Convert 79510 to Octal
  • Calculation Quotient Remainder
  • 795 / 8 99 3
  • 99 / 8 12 3
  • 12 / 8 1 4
  • 1 / 8 0 1
  • (Reading up) 79510 14338

Remember Read upwards!!
43
Hexadecimal Numbers (Base 16)
  • The octal system is a system based on sixteen
    numbers
  • 0,1,2,3,4,5,6,7,8,9, A,B,C,D,E,F
  • The numbers are represented as sums of the powers
    of sixteen

44
Hexadecimal to Decimal Conversion
  • Lets take the hexadecimal number 90FC16. What
    does this hexadecimal number represent as a
    number that humans would understand?
  • We could convert hexadecimal number to a decimal
    number

45
Rules to Convert Hexadecimal Number to Decimal
Number
  • Steps
  • Reading left to right, multiply placeholder (0
    through F) by the corresponding power of 16
  • Remember
  • A10, B11, C12, D13, E14, F15

46
Convert Hexadecimal to Decimal
  • 90FC16
  • 9x163 9 x 4096 36864
  • 0x162 0 x 256 0
  • 15x161 15 x 16 240
  • 12x160 12 x 1 12
  • Decimal 3711610

47
Convert Decimal to Hexadecimal
  • We convert from decimal to hexadecimal by a
    procedure similar to converting decimal to binary
  • Instead of successively dividing by 2, we
    successively divide by 16

48
Convert Decimal to Hexadecimal
  • Steps
  • 1. Divide the number by 16 and save the
  • quotient for the next step. Write the
  • remainder on the side
  • 2. If the quotient in step 1 is 0, stop
  • 3. If the quotient in step 1 is not 0, repeat
  • step 1, using the quotient as the new number
  • Obtain the answer by reading the remainders in
    the inverse order in which they are produced

49
Converting Decimal to Hexadecimal
  • Convert 42910 to Hexadecimal
  • Calculation Quotient Remainder
  • 429 / 16 26 D
  • 26 / 16 1 A
  • 1 / 16 0 1
  • 0 / 16
  • (Reading up) 42910 1AD16

Remember Read upwards!!
50
Numbering System Shortcuts
  • It is very simple to convert binary numbers to
    octal or hexadecimal numbers since 8 is 23, and
    16 is 24
  • In other words
  • 1 Octal digit 3 binary digits
  • 1 Hex digit - 4 binary digits

51
Binary to Octal
  • Notice the Pattern
  • Largest 3 digit binary is 111
  • 1 octal digit will represent a 3 digit binary
    number
  • Highest Octal digit is 7
  • Therefore 1112 78

52
Binary to Octal
  • Relationship
  • Octal Binary
  • 0 000
  • 1 001
  • 2 010
  • 3 011
  • 4 100
  • 5 101
  • 6 110
  • 7 111

Does this table look familiar?
53
Practical Example
  • applying octal values of rwx the chmod command
    (e.g., chmod 751).
  • chmod 777 - 111 111 111 - rwx rwx rwx
  • chmod 755 - 111 101 101 - rwx r-x r-x
  • chmod 711 - 111 001 001 - rwx --x --x
  • chmod 644 - 110 100 100 - rw- r-- r--

54
Binary to Hexadecimal
  • Notice the Pattern
  • Largest 4 digit binary is 1111
  • 1 hex digit will represent a 4 digit binary
    number
  • Highest hex digit is F
  • Therefore 11112 F16

55
Binary to Hexadecimal
  • Relationship
  • Hexadecimal Binary Hexadecimal Binary
  • 0 0000 8 1000
  • 1 0001 9 1001
  • 2 0010 A 1010
  • 3 0011 B 1011
  • 4 0100 C 1100
  • 5 0101 D 1101
  • 6 0110 E 1110
  • 7 0111 F 1111

56
Convert Hex to Binary
  • Steps
  • Convert Hex number to groups of powers of 2.
  • Convert to Binary number (Remember to drop
    leading zeros for first set of binary numbers -
    i.e. first left set)

57
Convert Hex to Binary
  • 11F616
  • 1 1 F
    6
  • 000(1) 000(1) (8)(4)(2)(1) 0(4)(2)0
  • 1 0001 1111 0110
  • 10001111101102

Drop Leading zeros
000
58
Convert Binary to Hex
  • Steps
  • Separate into 4 bit groups starting from the
    right.
  • Calculate decimal equivalent (in placeholders in
    powers of 2)
  • Convert to Hexadecimal number

59
Convert Binary to Hex
  • 10001111101102
  • 1 0001 1111 0110
  • 0001 0001 1111 0110
  • 1 1 (8)(4)(2)(1) 0(4)(2)0
  • 1 1 15 6
  • 11F616

60
Converting Octal to Hexadecimal
  • The easiest method to convert between Octal and
    Hexadecimal is to convert to binary as an
    intermediate step
  • Regroup binary in groups of 4 for hexadecimal and
    3 for octal

61
Storing Numbers
  • Numeric information (stored as a non negative
    number) is often store in a computer in binary.
  • Eg.
  • 1 byte (0 - 255 numbers)
  • 2 bytes (0 - 65535)
  • 4 bytes (0-4294967295)

62
Data Representation
  • So far, we have learned how to convert between
    decimal, binary, octal and hexadecimal numbering
    systems and have performed non-decimal
    arithmetic.
  • One of the main purposes of this topic is to
    represent numbers as binary code

63
Word Size
  • For PCs 8 bits is used to represent characters,
    but large number may require more than just 8
    bits.
  • The number of bits that can be received,
    processed and transferred from the CPU is
    referred to as the word size
  • PCs have 16 and 32 bit word sizes
  • Mainframes have 64 bit word sizes

64
Storing Numbers
  • Numeric information (stored as a non negative
    number) is often stored in a computer in binary.
  • Eg.
  • 1 byte (0 - 255 numbers)
  • 2 bytes (0 - 65535)
  • 4 bytes (0-4294967295)

65
Data Formats
  • Unsigned Binary
  • Data stored as a binary number, with no way to
    express a negative quantity

66
Unsigned Numbers
  • If the sign of the number is not important (ie.
    The number is not negative) then it is referred
    to as an unsigned number.
  • Decimal Number Ranges
  • 8 bits 0 - 255
  • 16 bits 0 - 65535
  • 32 bits 0 - 4294967295

67
Data Formats
  • Signed Binary
  • Data stored as a binary number, but using a
    leading zero to represent a positive number, and
    the twos complement of a binary number for a
    negative number

68
Signed Numbers
  • If the sign of the number does matter (ie. The
    number is positive or negative) then it is
    referred to as an signed number.
  • Decimal Number Ranges
  • 8 bits -128 to 127
  • 16 bits -32768 to 32767
  • 32 bits -214743648 to 2147483647

69
How to Store a Negative Number as Binary?
  • You should know how to represent an unsigned
    number or value as binary code.
  • How is a negative number stored as binary?
  • By using a mathematical construct referred to as
    Twos Complement

70
Adding / Subtracting Binary Numbers
  • Addition
  • 0 0 0
  • 0 1 1, 1 0 1
  • 1 1 10
  • Subtraction
  • 0 - 0 0
  • 1 - 1 0, 1 - 0 1
  • 0 - 1 (Must borrow from next placeholder)
  • Therefore 10 - 1 1

71
Twos Complement
  • Simple method of subtracting two binary numbers
    by adding.
  • Two Complement
  • Flip binary numbers (0 becomes 1, visa versa)
  • then add 1
  • Result becomes negative
  • Therefore, short-hand method of representing
    negative integers

72
Twos Complement
  • By performing the mathematical construct Twos
    Complement, a binary number can be stored as its
    opposite (to the computer, this represents a
    negative number)
  • Steps
  • Flip the digits of the binary number (ie. 1
    becomes a 0, and a 0 becomes a 1)
  • add 12

73
Twos Complement Example
  • Assuming a computer with a 16 bit word size, take
    the decimal number 48
  • Binary Number 00000000001100002
  • Flip Digits (Bits) 11111111110011112
  • Add 12 12
  • Twos Complement 11111111110100002

To the computer the binary number represents -48!
This wont work on your calculator...
74
Twos Complement
  • In order to store a signed number as binary in
    your computer, the first digit in the binary
    number is used to represent the sign of the
    number.
  • A binary number beginning with a 0 represents a
    positive number
  • A binary number beginning with a 1 represents a
    negative number

75
Twos Complement
  • Twos Complement also is used to simplify the
    mathematical operations of a computer
  • The number of circuits (processes) are fewer for
    adding numbers as opposed to subtracting numbers.
  • Therefore, to simplify the process (and save
    money) manufacturers prefer to add a positive and
    negative number as opposed to subtraction!

76
Twos Complement Exercise
  • Find the Twos Complement of 110012

77
Twos Complement Exercise
  • Determine whether the following 8-bit binary
    numbers are positive or negative
  • 100011112
  • 000011002
  • 111111112
Write a Comment
User Comments (0)
About PowerShow.com