一个short型值用十六位比特存储。编写程序,提示用户,输入一个短整形,然后显示这个整数的16比特形式运行示例
Enter an integer :5
the bits is 0000000000000101
求java代码 用位操作怎么做
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
3条回答 默认 最新
- threenewbee 2016-06-19 10:36关注
/* package whatever; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ class Ideone { public static void show(int n, int acc) { if (n < 0) n = 65536 + n; if (acc == 0) return; show(n >> 1, acc - 1); System.out.print(n % 2); } public static void main (String[] args) throws java.lang.Exception { System.out.print("5 the bits is "); show(5, 16); System.out.println(); System.out.print("-5 the bits is "); show(-5, 16); System.out.println(); } }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 像这种代码要怎么跑起来?
- ¥15 怎么改成循环输入删除(语言-c语言)
- ¥15 安卓C读取/dev/fastpipe屏幕像素数据
- ¥15 pyqt5tools安装失败
- ¥15 mmdetection
- ¥15 nginx代理报502的错误
- ¥100 当AWR1843发送完设置的固定帧后,如何使其再发送第一次的帧
- ¥15 图示五个参数的模型校正是用什么方法做出来的。如何建立其他模型
- ¥100 描述一下元器件的基本功能,pcba板的基本原理
- ¥15 STM32无法向设备写入固件