LEC20081120 - Introduction to Computer Programming November...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
Introduction to Computer Programming November 20, 2008 CSC180 Fall 2008, University of Toronto
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Bitwise operators Applicable to char, short, int, and long, signed or unsigned. In decreasing precedence, the bitwise operators are ~ one’s complement (unary) << >> left shift right shift bitwise AND ^ bitwise XOR (exclusive-or) | bitwise OR Example: let a patchwork be defined by f ( x, y ) = (( x y y - 350) ± 3)) 2 , where x is row index and y is column index. If ( f ( x, y ) ± is 1, paint the dot at ( x, y ) white, otherwise paint the dot at ( x, y ) black. CSC180 Fall 2008, University of Toronto 1
Background image of page 2
Code for the above example: /* patchwork.c -- designed by S. Sleator, 1976 */ #include <stdio.h> int f(int x, int y) { int t; t = (x ^ ~y) & ((y - 350) >> 3); t = t * t; return (t >> 12) & 1; } #define X 300 #define Y 300 int main() { int i, j; CSC180 Fall 2008, University of Toronto 2
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
for (j = 0; j < Y; j++) printf("%c", f(i, j) == 0 ? ’0’ : ’1’); printf("\n"); } return 0; } A patchwork produced using the above program: Exercise: let f ( x, y ) = ( x 2 y ± , 1 x, y 256 . Paint the dot at
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/10/2011 for the course CSC 180 taught by Professor Na during the Fall '01 term at University of Toronto- Toronto.

Page1 / 11

LEC20081120 - Introduction to Computer Programming November...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online