C程序 - 转换为二进制整数 [英] C Programming - Convert an integer to binary
问题描述
我是希望以后反对的解决方案,因为这一些技巧是功课,我想解决它自己
i was hopefully after some tips opposed to solutions as this is homework and i want to solve it myself
我首先很新的C.事实上,我从来没有做过任何之前,虽然我从在大学模块previous java的经验。
I am firstly very new to C. In fact i have never done any before, though i have previous java experience from modules at university.
我试图写在二进制一个整数转换的程序。我只允许使用位运算,没有库函数
I am trying to write a programme that converts a single integer in to binary. I am only allowed to use bitwise operations and no library functions
任何人都可以提出可能对我怎么会去这样做的一些想法。很明显,我不想code或任何东西,只是一些想法什么门路我有点困惑,并没有攻击计划,以探索为currenty。好了,让了很多困惑:D
Can anyone possibly suggest some ideas about how i would go about doing this. Obviously i dont want code or anything, just some ideas as to what avenues to explore as currenty i am a little confused and have no plan of attack. Well, make that a lot confused :D
非常感谢
推荐答案
想想你可以用按位运算符做什么。
Think about about what you can do with bitwise operators.
例如。您可以测试一个位是1或0这样的:
E.g. you can test whether a bit is 1 or 0 like this:
int bit = value & 1;
您也可以在这样一个int位转移:
You can also shift the bits in an int like this:
val = val >> 1;
要测试的第i位在一个int你可以这样做:
To test the i'th bit in an int you can do this:
int bit = (value >> i) & 1;
我希望这足够的提示,让你开始。
Hopefully that's enough hints to get you started.
这篇关于C程序 - 转换为二进制整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!