为什么要使用的不是普通基地10个号码的十六进制值? [英] Why use hex values instead of normal base 10 numbers?

查看:169
本文介绍了为什么要使用的不是普通基地10个号码的十六进制值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找在<一个href=\"http://www.ibm.com/developerworks/library/j-math1/index.html?ca=dgr-btw03JavaPart1&S_Tact=105AGX59&S_cmp=GRsitebtw03#hypotenuse\"相对=nofollow>这code 在Java中计算的Math.sqrt 。为什么他们使用一些循环和正​​常的变量值的十六进制值?有什么好处没有使用十六进制?

I was looking over this code to calculate math.sqrt in Java. Why did they use hex values in some of the loops and normal values for variables? What benefits are there to use hex?

推荐答案

由于六角更加紧密地对应于十进制数位。每个十六进制数字对应4位(半字节)。所以,一旦你学会了每个十六进制数(0-F)相关联的掩码,你可以这样做:我想为低位字节面具:

Because hex corresponds much more closely to bits that decimal numbers. Each hex digit corresponds to 4 bits (a nibble). So, once you've learned the bitmask associated with each hex digit (0-F), you can do something like "I want a mask for the low order byte":

0xff

或者,我要为底31位的面具:

or, "I want a mask for the bottom 31 bits":

0x7fffffff

仅供参考:

HEX    BIN
0   -> 0000
1   -> 0001
2   -> 0010
3   -> 0011
4   -> 0100
5   -> 0101
6   -> 0110
7   -> 0111
8   -> 1000
9   -> 1001
A   -> 1010
B   -> 1011
C   -> 1100
D   -> 1101
E   -> 1110
F   -> 1111

这篇关于为什么要使用的不是普通基地10个号码的十六进制值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆