[問題] bitwise and
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
g++
程式碼(Code):(請善用置底文網頁, 記得排版)
#include <iostream>
#include <cstdio>
using namespace std;
int main(){
int i=1;
while(1 &(1<<i) !=0){
printf("%d\n",1&(1<<i));
i++;
}
printf("Done!\n");
}
請問這個程式碼為什麼不會停呢?
但是把 while(1&(1<<i)!=0) 改成 while( 1&(1<<i) )
就會停了
但是我在while 裡面印出來1&(1<<i) 的值 明明都是0
怎麼會這樣呢? 是and 出來的結果直接跟 0 比對 會產生什麼誤會嗎?
謝謝
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 111.184.164.153
→
07/28 10:54, , 1F
07/28 10:54, 1F
→
07/28 10:55, , 2F
07/28 10:55, 2F
→
07/28 11:27, , 3F
07/28 11:27, 3F
→
07/28 11:29, , 4F
07/28 11:29, 4F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章