1. //请教一个笔试题,:
2. public static void main(String[] args) {
3. // TODO Auto-generated method stub
4. int i= 0xFFFFFFFA;
5. int j=~i;
6. System.out.println(i);
7. System.out.println(j);
8. }
9. /*结果为什么是:
10. -6
11. 5
12. 为什么*/
Answer:
引用
int i= 0xFFFFFFFA;
最高位F对应的2进制表示为1111,int是带符号的整数,最高位为1表示是个负数,负数在电脑中用补码表示,那就要计算出0xFFFFFFFA的补码。
原码=1111 1111 1111 1111 1111 1111 1111 1010
补码=1000 0000 0000 0000 0000 0000 0000 0101 还要+1就等于
1000 0000 0000 0000 0000 0000 0000 0110
第一个1表示负数,后面0110就是6 ,那么结果就是-6
引用
int j=~i;
~ 符号表示取反
i=1111 1111 1111 1111 1111 1111 1111 1010 ,取反则为
j=0000 0000 0000 0000 0000 0000 0000 0101 就等于5了。
分享到:
相关推荐
Bitwise是一个教育项目,能让我们从头开始为计算机创建软件/硬件堆栈
Bitwise operation are really joy to use
A test harness that checks a student's solution in bits.c
OpenCV-Python图像位与运算bitwise_and函数详解.rar
—如何使用import bitwiseRotation from 'bitwise-rotation' ;// Set the bit-width/length; max of `32`, min of `0`.const rotationObject = bitwiseRotation ( 8 ) ;// Returns an object with rotate right (`...
bitwise.zip
Matlab practical guide instance M file
poj 3495 Bitwise XOR of Arithmetic Progression.md
使用 PHP 构建的高级 Web 框架,灵活且速度非常快
import bitwise from 'bitwise' const bits = bitwise . byte . read ( 42 ) // [0, 0, 1, 0, 1, 0, 1, 0] bitwise . bits . toString ( bits , 4 ) // '0010 1010' bitwise . byte . write ( bits ) // 42 bitwise...
Laravel开发-laravel-bitwise-trait 在任何类上使用位运算符的简单特性
The decoding algorithm used in RBDS.c is based on error... The program emulates the operation of the encoder and decoder of a binary cyclic codes, using bitwise shifts and xor for modulo g(x) operations.
华为一个WCDMA路测仪表说明,有部分界面设计和功能参考价值,希望对大家有用
不伦瑞克科学博览会项目旨在将代码片段演变为复杂的有机体。 用Java编程
指向一个和数据一样大的字符数组如果 A 是数据的类型,则char* ptr = new char[sizeof(A)] 请注意, sizeof(A)以字节为单位返回大小我使用了unsigned char因为它看起来更合适将数据从数据复制到指针这行对我来说看...
算术逻辑部件的verilog代码,它能够实现半加器、全加器、比较、按位与、按位或、按位异或、加一、减一的操作
opencv按位计算 配合博文使用
富士Bitwise 具有按位功能的NetCOBOL库 模块总结 名称 描述 将一个字节转换为十六进制表示形式。 将十六进制转换为二进制。...l-arg-a一个字节l-arg-b一个字节 退货 一个字节 宾和 使用l-arg-a,l-arg-b调用
元胞自动机(CA)理论是一个离散模型,它代表一组有限的可能值,这些值根据预先定义的过渡规则随时间演变,从而表示每个单元的状态。 CA已经被应用于许多图像处理任务,例如凸包检测,图像去噪等,但是大多受到将...