[問題] bitwise operator "<<" 的問題
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
Ubuntu 10.04
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
問題(Question):
0110 是八進位表示法 改成十進位是 72
向左移一位後是1100, 十進位表示法應該是 8^3 + 8^2 = 512 + 64 = 576
可是輸出結果為144, 是不是我搞錯 "<<" 這個operator 的意思??
麻煩版上高手解惑, 謝謝~~
餵入的資料(Input):
gcc test.c
./a.out
預期的正確結果(Expected Output):
72
576
錯誤結果(Wrong Output):
72
144
程式碼(Code):(請善用置底文網頁, 記得排版)
#include<stdio.h>
int main()
{
int p;
p=0110;
printf("%d\n",p);
p=p<<1;
printf("%d\n",p);
return 0;
}
補充說明(Supplement):
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 218.173.120.148
→
08/15 23:34, , 1F
08/15 23:34, 1F
→
08/16 00:13, , 2F
08/16 00:13, 2F
→
08/16 00:14, , 3F
08/16 00:14, 3F
推
08/21 18:34, , 4F
08/21 18:34, 4F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章