Re: c語言的問題
※ 引述《shackles@kkcity.com.tw (隨風而逝)》之銘言:
> 我想將一個unsigned整數位元反轉,但是程式已經寫好一個副函式了,
> 如果我想將位元順序反轉輸出,得用到指標嗎?
不用吧
main()
{
unsigned int mask = 1 << 31, n = 74111608;
int i;
for (i = 0; i < 32; i++) {
printf("%d", (n & mask) ? 1 : 0);
mask >>= 1;
}
return 0;
}
以上是正常順序的輸出,MSB在左,LSB在右
你把他改一下就可以反轉了
--
美國戰後戰鬥機發展時程,F-80 - XF-108 : http://blog.bs2.to/post/GOLDMEMBER/8981
The UNIVAC Biblestory : http://blog.bs2.to/post/GOLDMEMBER/9041
The James Bond Superweaponry : http://blog.bs2.to/post/GOLDMEMBER/9002
今日的一言(2/10): 登月演說, 1962 : http://blog.bs2.to/post/GOLDMEMBER/7840
http://blog.bs2.to/GOLDMEMBER 法外科學暨工程顧問公司
--
▄▄▄▄▄▄▄ ▄▄▄▄ ▄▄▄▄▄▄ <telnet://bbs.cs.nctu.edu.tw>
█▄▄▄▄█ █ ▄▄▄▄▄█ Player: GOLDMEMBER
▄█▄▄▄▄█ ▄▄▄█ █▄▄▄▄▄ From: 218-160-85-94.dynamic.hinet
☆ 次世代BS2 ☆ 可申請個人板 150MB 相簿 http://pic.bs2.to 交大資訊人 250MB
討論串 (同標題文章)