AP Computer Science A

- Conversion


Limits of the AP CS Syllabus
Learning Objectives:
Essential Knowledge:
The Binary System

Bits and Bytes
Character Set
Character Representation
ASCII (American Standard Code for Information Interchange)
Unicode
ASCII codes
Representing Characters and Numbers Examples
Binary Arithmetic Rules
  1
+ 1
1 0

Please note that our "normal" decimal base 10 system does this "carry & reset" at 10, but binary being base 2, "carries & resets" at 2.
  1
  1
+ 1
1 1


ASCII Arithmetic
  0       00110000
+ 1     + 00110001
  1       01100001   i.e. not 00110001 like it ahould be!
          01100001  (carries)


Decimal or Denary System
100 10 1
1 3 4


Binary Number System
Binary Number
128 64 32 16 8 4 2 1
 
Denary Number
0

Exploding Dots

Denary -> Binary e.g. 117
  1. Write the column headings for a byte (8 bits).
  2. 117 < 128 so put a 0 in the '128' column and move to the next column heading.
128 64 32 16 8 4 2 1
0
  1. 117 > 64 so put a 1 in the '64' column, subtract 64 from the denary number being converted to binary (117 - 64 = 53) and move to the next column heading.
128 64 32 16 8 4 2 1
0 1
  1. 53 > 32 so put a 1 in the '32' column, further subtract 32 from the denary number being converted to binary (53 - 32 = 21) and move to the next column heading.
128 64 32 16 8 4 2 1
0 1 1
  1. 21 > 16 so put a 1 in the '16' column, further subtract 16 from the denary number being converted to binary (21 - 16 = 5) and move to the next column heading.
128 64 32 16 8 4 2 1
0 1 1 1
  1. Continue this process until the entire number has been converted (if any bits remain unused they should be 0).
128 64 32 16 8 4 2 1
0 1 1 1 0 1 0 1

Decimal -> Binary Practice
Binary -> Denary e.g. 10110110
  1. Put the column headings above the binary number and add up all the columns with a 1 in them.
128 64 32 16 8 4 2 1
1 0 1 1 0 1 1 0
  1. So 10110110 = 128 + 32 + 16 + 4 + 2 = 182 (denary)
8 bit patterns
Binary -> Decimal Practice
Largest number

Two's Complement
Binary Number
-128 64 32 16 8 4 2 1
 
Denary Number
0

Overflow Problem with Two's Complement
but


  0 1 1 0 0 1 1 0
+ 0 1 1 1 0 1 0 1
  1 1 0 1 1 0 1 1 = -37
  1 1     1 (carries)
Fixed Point Binary
Binary Number
Integer Fraction
-8 4 2 1 . 1/2 1/4 1/8 1/16
0 1 1 0 1 1 0 0

Binary Number
Integer Fraction
-8 4 2 1 . 1/2 1/4 1/8 1/16
 
Denary Number
0

Fixed Point Binary Precision
Standard Form / Scientific Notation
Floating Point (Fractional Real Numbers)
Mantissa   Exponent
Fraction Decimal  
0
Decimal Number
0
0
* 2 =
0
Mantissa Exponent
-1 . 1/2 1/4 1/8 1/16 1/32 1/64 1/128 -128 64 32 16 8 4 2 1
Not normalised!
 


Binary Fractional Precision