開発環境
- OS X Lion - Apple(OS)
- TextWrangler(Text Editor) (BBEditの無料、light版)
- 言語: C
- コンパイラ: UNIX ccコンパイラ (汎用UNIX)
『実践プログラミング 第3版』 (Steve Oualline (著)、 望月 康司 (監修) (翻訳)、 谷口 功 (翻訳)、 オライリー・ジャパン、1998年、ISBN978-4900900646) の11章(ビット演算)11.9(プログラミング実習)j実習11-2.を解いてみる。
実習11-2.
コード(TextWrangler)
#include <stdio.h> #define X_SIZE 10 #define Y_SIZE 10 char graphics[X_SIZE / 8][Y_SIZE]; #define SET_BIT(x,y) graphics[(x) / 8][y] |= (0x80 >> ((x) % 8)) int main(){ int loc; void print_graphics(void); for(loc = 0; loc < X_SIZE; ++loc){ SET_BIT(loc,loc); } print_graphics(); return (0); } void print_graphics(void){ int x; int y; unsigned int bit; for(y=0; y < Y_SIZE; ++y){ for(x = 0; x < X_SIZE / 8; ++x){ for(bit = 0x80; bit > 0; bit =(bit>>1)){ printf("X"); } } printf("\n"); } }
入出力結果(Terminal)
$ cc -g -o sample sample.c $ ./sample XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX $
フォントの影響で正方形っぽくないけどこれでいいのかな。。
0 コメント:
コメントを投稿