CPSC 233 Tutorial

12
CPSC 233 Tutorial Xin Liu 2011/01/17

description

CPSC 233 Tutorial. Xin Liu 2011/01/17. Self-intro. Xin Liu PhD student Email: [email protected] 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: - PowerPoint PPT Presentation

Transcript of CPSC 233 Tutorial

Page 1: CPSC 233 Tutorial

CPSC 233 TutorialXin Liu

2011/01/17

Page 2: CPSC 233 Tutorial

Self-intro Xin Liu PhD student Email: [email protected] Homepage:

http://pages.cpsc.ucalgary.ca/~liuxin CT: Thursday 12:00-2:00 @ CT desk

Page 3: CPSC 233 Tutorial

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

Page 4: CPSC 233 Tutorial

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 -c 233 -a 3 a3.p README

List submitted files showstuff -c <course number> -a <assignment number> eg. showstuff -c 233 -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

Page 5: CPSC 233 Tutorial

Binary Numbers

hexadecimal Binary hexadecimal Binary

0x0 0000 0x8 10000x1 0001 0x9 10010x2 0010 0xA / 10 10100x3 0011 0xB / 11 10110x4 0100 0xC / 12 11000x5 0101 0xD / 13 11010x6 0110 0xE / 14 11100x7 0111 0xF / 15 1111

Byte: 8 bits Word: 16 bits Double word: 32 bits Quad word: 64 bitsMultiples of 4 bits, corresponding to a hexadecimal number

Page 6: CPSC 233 Tutorial

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 …

Page 7: CPSC 233 Tutorial

Dec Bin Convert Integer and Decimal parts

seperately Example: 37.43 100101.01101b

Page 8: CPSC 233 Tutorial

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)

Page 9: CPSC 233 Tutorial

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 1111true code

1010 0000 Flip (one’s complement)

1010 0001 +1

Page 10: CPSC 233 Tutorial

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)

Page 11: CPSC 233 Tutorial

Integer Subtraction x - y = x + two’s complement of y Procedures:

Compute the two’s complement of y (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)

Page 12: CPSC 233 Tutorial

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)