看板Programming
标 题Re: c语言的问题
发信站交大资讯次世代BS2 (Thu May 17 02:45:39 2007)
转信站ptt!ctu-reader!ctu-gate!news.nctu!news.ntust!news.cis.nctu!BS2
※ 引述《[email protected] (随风而逝)》之铭言:
> 我想将一个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