開発環境
- OS X Mavericks - Apple(OS)
- Emacs (CUI)、BBEdit - Bare Bones Software, Inc. (GUI) (Text Editor)
- C (プログラミング言語)
- Clang (コンパイラ)
C実践プログラミング 第3版 (Steve Oualline (著)、 望月 康司 (監訳) (翻訳)、谷口 功 (翻訳)、オライリー・ジャパン)のⅡ部(単純なプログラミング)の11章(ビット演算)、11.1(ビット演算子)、11.2(AND 演算子(&))、設問を解いてみる。
その他参考書籍
- プログラミング言語C 第2版 ANSI規格準拠 (B.W. カーニハン D.M. リッチー (著)、 石田 晴久 (翻訳)、共立出版)
- プログラミング言語Cアンサー・ブック 第2版 (クロビス・L.トンド、スコット・E.ギンペル(著)、矢吹 道郎(翻訳))
設問.
コード
sample.c
#include <stdio.h>
int main()
{
int i1, i2;
i1 = 4; /* binary 0100 */
i2 = 2; /* binary 0010 */
if ((i1 != 0) && (i2 != 0)){
printf("Both are not zero #1 \n");
}
if (i1 && i2){
printf("Both are not zero #2 \n");
}
/* i1 & i2 = binary 0000 */
/* 0000 (10進数では0)は偽となるから出力されない */
if (i1 & i2){
printf("Both are not zero #3 \n");
}
return (0);
}
makefile
CC=cc CFLAGS=-g sample: sample.c $(CC) $(CFLAGS) -o sample sample.c clean: rm -f sample
入出力結果(Terminal)
$ make cc -g -o sample sample.c $ ./sample Both are not zero #1 Both are not zero #2 $
0 コメント:
コメントを投稿