十进制到二进制转换程序 [英] Decimal to Binary Conversion program
问题描述
嗨伙计们
i我试图制作一个程序将十进制数转换成二进制数...我能够做到这一点,但数字反转..就像1101像1011一样
现在我怎么把它换掉..
这里是代码
hi guys
i am trying to make a program to convert decimal number into binary .. i am able to do that, but the number comes inverted.. like 1101 comes like 1011
now how do i swap it off..
here is teh code
推荐答案
hi guys
i我试图制作一个程序将十进制数转换成二进制..我能够做到这一点,但数字倒转..喜欢1101就像1011
现在怎么把它换掉..
hi guys
i am trying to make a program to convert decimal number into binary .. i am able to do that, but the number comes inverted.. like 1101 comes like 1011
now how do i swap it off..
你不能;您应该阅读 Integer 类的API文档。它就在那里。
亲切的问候,
Jos
You don''t; you should read the API documentation for the Integer class. It''s all there.
kind regards,
Jos
你不是;您应该阅读 Integer 类的API文档。它就在那里。
亲切的问候,
Jos
You don''t; you should read the API documentation for the Integer class. It''s all there.
kind regards,
Jos
hi jos,
我知道有一个直的函数整数(11,2)..但我想通过逻辑来实现..
因为这是我的任务..谢谢:)
hi jos,
I know there is a straight function integer(11,2) .. but i wanna make it thru logic..
cause that is my assignment.. thanks :)
hi jos,
我知道有一个直的函数整数(11,2)..但我想通过逻辑...
因为这是我的任务..谢谢:)
hi jos,
I know there is a straight function integer(11,2) .. but i wanna make it thru logic..
cause that is my assignment.. thanks :)
递归是你的朋友(它避免在最后反转整个事情)。
假设你有一个数字''n' '小于2:结果将是0。或1或1。然后;否则
结果将是数字n / 2的二进制字符串表示,附加
n%2的二进制字符串表示。你甚至可以通过一点点移动避免分裂和
模数(提示:>>>>和<<<<<<<<<<<<<<<<<<亲切的问候,
Jos
Recursion is your friend then (it avoids reversing the entire thing at the end).
Suppose you have a number ''n'' less than 2: the result will be "0" or "1" then; otherwise
the result will be the binary string representation of the number n/2 appended with
the binary string representation of n%2. You can even avoid the division and
modulo by a bit of bit shifting (hint: >>> and <<).
kind regards,
Jos
这篇关于十进制到二进制转换程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!