How Computers Represent Information - PowerPoint PPT Presentation

About This Presentation
Title:

How Computers Represent Information

Description:

How Computers Represent Information Yong Choi School of Business CSU, Bakersfield – PowerPoint PPT presentation

Number of Views:77
Avg rating:3.0/5.0
Slides: 18
Provided by: ych84
Learn more at: https://www.csub.edu
Category:

less

Transcript and Presenter's Notes

Title: How Computers Represent Information


1
How Computers Represent Information
  • Yong Choi
  • School of Business
  • CSU, Bakersfield

2
Digital Storage
  • Humans decimal (or base 10) number system
  • Computer binary (base 2) number system
  • On (high or 1)
  • Off (low or 0)
  • Each digit in a binary number is known as a bit
    and can have only one of two values, 0 or 1.
  • One bit can store a number from 0 to 1
  • Two bits can store from 0 to 3
  • n bits can store numbers from 0 to 2n

3
Binary Numbers
  • Programmers often need to read numbers in the
    computer because the number of bits in
    calculation affects the accuracy and size
    limitations of numbers manipulated by the
    computer.
  • So, it is useful to understand how the binary
    number system is used within the computer.
  • In Java, programmer can declare a variable to be
    short (16 bits) and or long (64 bits) integer
    depending on the anticipated size of the number
    being used and required accuracy in calculations.

4
Advantages of Binary Numbers
  • Simple
  • Only two O and 1
  • Unambiguous and clear signals
  • Analog signal vs. Digital signal
  • Flawless copies can be made
  • Anything (English, Spanish, Chinese) can be
    represented with patterns of bits

5
Hexadecimal Numbers
  • Important!! Because it is commonly used as a
    shorthand notation for binary numbers.
  • Each hexadecimal number exactly represent 4
    binary bits.
  • Most computers store and manipulate instructions
    and data using word sizes that are multiple of 4
    bits.
  • Colors in VB can be specified as a six-digit
    hexadecimal number.
  • http//www.mrs.umn.edu/committees/wwwac/toolbox/co
    lor.html

6
Review of Decimal Numbers
  • Decimal numbers are based on powers of 10.
    Mathematically, the number 537 can be
    calculated..
  • Similarly 9238 is
  • 9 103 2 102 3 101 8 100

5 102 3 101 7 100
5 100 3 10 7 1
500 30 7
7
Converting Binary to Decimal
  • Easy, just multiply digit by power of 2
  • Binary numbers are based on power of 2.
  • Just like a decimal number is represented
  • So, 101 binary is
  • 1 22 0 21 1 20 5
  • or
  • 1 4 0 2 1 1 5

8
Binary to Decimal Example
7 6 5 4 3 2 1 0
27 26 25 24 23 22 21 20
128 64 32 16 8 4 2 1
What is 10011100 in decimal?
1 0 0 1 1 1 0 0
128 0 0 16 8 4 0 0
156 27 1 26 0 ..
9
Converting Decimal to Binary
  • A little more work than binary to decimal
  • Find largest power-of-two smaller than decimal
    number
  • Make the appropriate binary digit a 1
  • Subtract the power of 2 from decimal
  • Do the same thing again
  • Some examples
  • 3 2 1 11 (thats 121 120)
  • 5 4 1 101 (thats 122 021 120)

10
Decimal to Binary Example
  • Convert 28 decimal to binary
  • 28/2 12 . 0
  • 12/2 10 . 0
  • 10/2 5 0
  • 5/2 4 .. 1
  • 4/2 2 .. 0
  • 2/2 1 .. 0

Answer 1001000
11
Converting Hex to Binary
  • Hexadecimal table

Dec Bin Hex
0 0000 0
1 0001 1
2 0010 2
3 0011 3
4 0100 4
5 0101 5
6 0110 6
7 0111 7
Dec Bin Hex
8 1000 8
9 1001 9
10 1010 a
11 1011 b
12 1100 c
13 1101 d
14 1110 e
15 1111 f
12
Hex to Binary Example
  • Hex to Binary just convert digits

2ac
2ac 001010101100
No magic!! - remember each hex digit 4 bits
13
Binary to Hex
  • Just convert groups of 4 bits

101001101111011
1011
0101 ?
0111 ?
0011 ?
101001101111011 537b
14
Hex to Decimal
Dec Hex
0 0
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
10 a
11 b
12 c
13 d
14 e
15 f
  • Just multiply each hex digit by decimal value,
    and add the results.

2ac
2 256
10 16
12 1
684
???? ???? ???? ????
163 162 161 160
4096 256 16 1
15
Decimal to Hex
  • Analogous to decimal ? binary.
  • Find largest power-of-16 smaller than decimal
    number
  • Divide by power-of-16. The integer result is hex
    digit.
  • The remainder is new decimal number.
  • Do the same thing again

16
Decimal to Hex
Dec Hex
0 0
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
10 a
11 b
12 c
13 d
14 e
15 f
684
2__
684/256 2
684/256 172
2a_
172/16 10 a
172/16 12 c
2ac
???? ???? ???? ????
163 162 161 160
4096 256 16 1
17
Exercise Questions
  • Convert decimal value 110 to
  • Binary
  • Hexadecimal
  • Convert binary value 1100111 to
  • Decimal
  • Hexadecimal
  • Convert hexadecimal value 6CAD to
  • Decimal
  • Binary
Write a Comment
User Comments (0)
About PowerShow.com