[問題] 為什麼這兩種寫法 出來的結果相異(有關 …
在練習位元邏輯運算子 的語法時
發現底下第二種寫法 跟第一種寫法
跑出來的結果不一樣
想請問一下是第二種寫法
哪裡出了問題呢
第一種寫法:(跑出來的結果是65435)
#include <iostream>
#include <stdlib.h>
using namespace std;
int main(void)
{
unsigned short int x=100,xx=~x;
cout << "x=01100100\n";
cout << "not x ==> " << xx << "\n";
system("pause");
return 0;
}
第二種寫法(跑出來的結果是-101):
#include <iostream>
#include <stdlib.h>
using namespace std;
int main(void)
{
unsigned short int x=100;
cout << "not x ==> " << ~x << "\n";
system("pause");
return 0;
}
推
07/21 18:32, , 1F
07/21 18:32, 1F
對 我打錯了orz
應該印的是xx
上面的文章改過來了|||
→
07/21 18:40, , 2F
07/21 18:40, 2F
但即使我把第一種寫法的
unsigned short int x=100,xx=~x;
改成
unsigned short int x=100;
xx=~x;
第一種寫法跑出來的結果還是65435
所以這邊應該不是,的問題|||
→
07/21 18:41, , 3F
07/21 18:41, 3F
→
07/21 18:41, , 4F
07/21 18:41, 4F
謝謝 第二種寫法 跟第一種寫法
跑出一樣的東西了!
推
07/21 18:45, , 5F
07/21 18:45, 5F
sorry|||
是我內文打錯了|||
→
07/21 18:47, , 6F
07/21 18:47, 6F
沒錯XD|||
※ 編輯: bookticket 來自: 140.112.125.84 (07/21 18:51)
推
07/21 18:58, , 7F
07/21 18:58, 7F
→
07/21 18:59, , 8F
07/21 18:59, 8F
推
07/21 19:05, , 9F
07/21 19:05, 9F
→
07/21 19:05, , 10F
07/21 19:05, 10F
→
07/21 19:11, , 11F
07/21 19:11, 11F
→
07/21 19:13, , 12F
07/21 19:13, 12F
→
07/21 19:14, , 13F
07/21 19:14, 13F
推
07/21 19:15, , 14F
07/21 19:15, 14F
→
07/21 19:17, , 15F
07/21 19:17, 15F
→
07/21 19:18, , 16F
07/21 19:18, 16F
推
07/22 00:29, , 17F
07/22 00:29, 17F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章