Week 07 Notes for CST8281 - Fall 2011

Ian! D. Allen - idallen@idallen.ca - www.idallen.com

Fall 2011 - September to December 2011 - Updated 2011-10-19 07:18 EDT

1 Lecture Notes for This WeekIndexup to index

1.2 From Blackboard Course DocumentsIndexup to index

These documents have restricted distribution and cannot be put on the Course Home Page.

1.3 From the InternetIndexup to index

1.4 From the Classroom Whiteboard/ChalkboardIndexup to index

1.4.1 Character EncodingIndexup to index

  • Character codes: ASCII, extended ASCII, EBCDIC, Unicode, UTF-8
    • ASCII Control Characters (unprintable)
    • line ends for text files on Unix/Mac/Windows
    • reading character tables
    • compare ASCII & EBCDIC for sort order and common printable characters
    • ASCII puts ‘A’ before ‘a’; EBCDIC does the reverse
    • tabs vs. spaces
    • know the Seven Famous ASCII Characters
      • 0D 0A 20 30 41 61 7F
    • do not memorize any EBCDIC
    • how to print the decimal value of 00001111(2) on the screen in ASCII?
      • decimal value is 15: send 31h and 35h (“1” and “5”)
  • Problems with all the 8-bit extended-ASCII character sets
    • can’t have Latin1 French and Latin2 Polish in the same text file: why?
  • UTF-8 advantages and disadvantages
    • same as ASCII, no endian-ness, multi-byte, full Unicode, may require more bytes than Unicode due to encoding scheme
  • Fonts vs. Character codes
    • codes only say what letter, not what it looks like
  • Why can’t French (Latin1) and Polish (Latin2) exist in the same text file?
    • same problem for all the 8-bit extended-ASCII character sets
  • How many ASCII characters are there?
  • What is the difference between ‘A’ and ‘a’? ‘M’ and ‘m’? ‘Z’ and ‘z’?
  • How many ASCII control characters (unprintable) are there?
    • what are their hex values?

1.4.2 Boolean Algebra / Bitwise OperatorsIndexup to index

  • Shifting numbers right and left
    • shifiting effect on two’s complement numbers: does it work?
    • Arithmetic Right Shift vs. Logical Right Shift
      • duplicate the top (carry) bit for Arithmetic Right Shift
    • F4240h = 1,000,000(10)
      • so F42400h = 1,000,000 * 16 = 16,000,000
      • so F424h = 1,000,000/16 = 1000000 * 0.0625 = 100 * 625 = 62,500
    • 03641100(8) = 1,000,000(10)
      • so 036411000 = 1,000,000 * 8 = 8,000,000
    • 1010(2) = 10 decimal
      • so 101000(2) = 10 * 2 * 2 = 40 decimal
  • Bitwise Operators AND, OR, XOR, NOT (in Java: & | ^ ~)
    • don’t confuse bitwise with logical: & with &&, | with ||, or ~ with !
    • if x=1, y=2 then x&y = 0 (no bits in common)
    • if x=6, y=12 then x&y = 4 (one bit in common)
    • XOR is Exclusive OR - A or B but not both
      • true OR true is true
      • true XOR true is false
    • if a=6,b=3 what is a&b? what is a|b? what is a^b? what is ~a?
    • if a=5,b=10 what is a&b? what is a|b? what is a^b? what is ~a?
  • Note: All integer types in Java are signed (except char)!
  • Conversions between upper/lower in ASCII using bitwise OR and AND:
    • 'A' | ' ' = 'a' (OR turns on the 20h bit, making it lower-case)
    • 'a' & ~' ' = 'A' (AND turns off the 20h bit, making it upper-case)
  • ASCII parity bit, used to detect errors in data transmission
    • is ‘A’ even or odd parity? convert it to even parity, then to odd
    • is CR even or odd parity? convert it to even parity, then to odd
  • Simplifying complex logic using Boolen Algebra - identities - deMorgan
    1. simplify: if ((x < y) && (y < z)) || ((x < y) && (y >=z ))
      • simplifies to just if (x < y) because:
      • let a = (x<y) and b = (y<z), therefore b' = (y>=z)
      • rewrite ab+ab' = a(b+b') = a(1) = a = (x<y)
    2. suppose a stale order means: date > 120 and amount > 0
      1. simplify: print unless stale
        • unless stale means if NOT stale
        • print if NOT (date > 120 && amt > 0)
        • using deMorgan: print if (date <= 120 || amt <= 0)
      2. simplify: print unless (stale and amt < 0)
        • print if NOT (stale && amt < 0)
        • print if ( !stale || amt >= 0)
        • print if ( date <= 120 || amt <= 0 || amt >= 0)
        • print if ( date <= 120 || TRUE )
        • therefore: always print (probably an error in the specifications!)
    3. Show that (xy + x'z + yz')' = y'(x+z')
      • (x'+y')(x+z')(y'+z) -- deMorgan
      • (x'x + x'z' + xy' + y'z')(y'+z) -- expand first two expressions
      • ( 0 + x'z' + xy' + y'z')(y'+z) -- identities
      • x'y'z' + x'z'z + xy'y' + xy'z + y'y'z' + y'z'z -- expand again
      • x'y'z' + 0 + xy' + xy'z + y'z' + 0 -- identities
      • x'y'z' + y'z' + xy' + xy'z -- regroup similar terms
      • y'z' + xy' -- absorption rule
      • y'(x+z') -- QED

2 Midterm Test #1 - 15%Indexup to index

3 Self-Mark 03Indexup to index

4 Self-Mark 04Indexup to index

Author: 
| Ian! D. Allen  -  idallen@idallen.ca  -  Ottawa, Ontario, Canada
| Home Page: http://idallen.com/   Contact Improv: http://contactimprov.ca/
| College professor (Free/Libre GNU+Linux) at: http://teaching.idallen.com/
| Defend digital freedom:  http://eff.org/  and have fun:  http://fools.ca/

Plain Text - plain text version of this page in Pandoc Markdown format

Campaign for non-browser-specific HTML   Valid XHTML 1.0 Transitional   Valid CSS!   Creative Commons by nc sa 3.0   Hacker Ideals Emblem   Author Ian! D. Allen