120 likes | 274 Views
CPSC 233 Tutorial. Xin Liu 2011/01/17. Self-intro. Xin Liu PhD student Email: liuxin@ucalgary.ca Homepage: http://pages.cpsc.ucalgary.ca/~liuxin CT: Thursday 12:00-2:00 @ CT desk. Unix Environment. Working in the lab is suggested Remote access using SSH On Windows:
E N D
CPSC 233 Tutorial Xin Liu 2011/01/17
Self-intro • Xin Liu • PhD student • Email: liuxin@ucalgary.ca • Homepage: http://pages.cpsc.ucalgary.ca/~liuxin • CT: Thursday 12:00-2:00 @ CT desk
Unix Environment • Working in the lab is suggested • Remote access using SSH • On Windows: • Download SSH Client program from http://www.ucalgary.ca/it/software/ssh • Quick Connect • Host Name: csc.cpsc.ucalgary.ca • User Name: xxx • On Mac: • using terminal to connect to the UNIX system • ssh <username>@csc.cpsc.ucalgary.ca
Assignment • Submit your Assignments with “submit” command of UNIX • Submit • submit -c <course number> -a <assignment number> <name of file or files to be submitted> • eg. submit -c233 -a 3 a3.p README • List submitted files • showstuff -c <course number> -a <assignment number> • eg. showstuff -c233 -a 3 • Submit early and update • Avoid plagiarism • MOSS ( Measure of Software Similarity )http://theory.stanford.edu/~aiken/moss/ • Cite if necessary • No marks lost by citing example code from TA/instructor
Binary Numbers Byte: 8 bits Word: 16 bits Double word: 32 bits Quad word: 64 bits Multiples of 4 bits, corresponding to a hexadecimal number
Bin Dec • 101011.0101 • 1*25 + 0*24 + 1*23 + 0*22 + 1*21 + 1*20 + 0*2-1 + 1*2-2 + 0*2-3 + 1*2-4 = 32 + 0 + 8 + 0 + 2 + 1 + 0 + 0.25 + 0 + 0.0625 = 43.3125 • Other examples …
Dec Bin • Convert Integer and Decimal parts seperately • Example: 37.43 100101.01101b
Negative Integers • Three representations • Regular binary (true code) • 0110 0100 (DEC 100) • 1110 0100 (DEC -100) • One’s complement (flip each bit) • 0110 0100 (DEC 100) • 1001 1011 (DEC -100) • Two’s complement (flip each bit + 1) most useful!!! • 0110 0100 (DEC 100) • 1001 1100 (DEC -100)
Negative integers • Two’s complement • Definition: 2N-x for an N-bit number • Regular binary two’s complement: • Positive: No change • Negative: flip bitwise + 1 Dec: - 95 10100001 ----------------------------- 95: - 0101 1111 true code 1010 0000 Flip (one’s complement) 1010 0001 +1
Integer Addition • Directly add the numbers, no matter positive or negative • Check left two carry bit • 00 or 11 valid • 01 or 10 invalid (overflow) 11111 111 (carry) 0000 1111 (15) + 1111 1011 (-5) ================== 0000 1010 (10) 0111 (carry) invalid! 0111 (7) + 0011 (3) ============= 1010 (−6)
Integer Subtraction • x-y=x+ two’s complement of y • Procedures: • Compute the two’s complement ofy(flip bits + 1) • Addition • Check for overflow 01100100 (x, equals decimal 100) - 00010110 (y, equals decimal 22) ========== 11100000 (carry) valid! 01100100 (x) + 11101010 (two’s complement of y) ========== 101001110 (two’s complement of result) 01001110 (regular binary of result 78)
Integer Subtraction • Another example 01100100 (x, equals decimal 100) --11001000 (y, equals decimal -200) ========== 01100000 (carry) invalid! 01100100 (x) + 00111000 (two’s complement of y) ========== 010011100 (two’s complement of result) - 01100100 (regular binary of result -196)