简体   繁体   English

0x0F 是什么意思? 这段代码是什么意思?

[英]What does 0x0F mean? And what does this code mean?

I have this code.我有这个代码。 Please make me understand what does this code actually mean请让我明白这段代码的实际含义

  for(var i = 0; i < input.length; i++)
  {
    x = input.charCodeAt(i);
    output += hex_tab.charAt((x >>> 4) & 0x0F)
           +  hex_tab.charAt( x        & 0x0F);
  }

What is 0x0F?什么是 0x0F? And, >>> Mean?而且,>>> 是什么意思?

>>> is the unsigned bitwise right-shift operator. >>>是无符号按位右移运算符。 0x0F is a hexadecimal number which equals 15 in decimal. 0x0F是十六进制数,十进制数等于 15。 It represents the lower four bits and translates the the bit-pattern 0000 1111 .它代表低四位并转换位模式0000 1111 & is a bitwise AND operation. &是按位AND运算。

(x >>> 4) & 0x0F gives you the upper nibble of a byte. (x >>> 4) & 0x0F给你一个字节的高半字节。 So if you have 6A , you basically end up with 06 :所以如果你有6A ,你基本上会得到06

6A = ((0110 1010 >>> 4) & 0x0F) = (0000 0110 & 0x0F) = (0000 0110 & 0000 1111) = 0000 0110 = 06

x & 0x0F gives you the lower nibble of the byte. x & 0x0F为您提供字节的低半字节。 So if you have 6A , you end up with 0A .所以如果你有6A ,你最终会得到0A

6A = (0110 1010 & 0x0F) = (0110 1010 & 0000 1111) = 0000 1010 = 0A

From what I can tell, it looks like it is summing up the values of the individual nibbles of all characters in a string, perhaps to create a checksum of some sort.据我所知,它看起来像是对字符串中所有字符的各个半字节的值求和,也许是为了创建某种校验和。

0x0f is a hexadecimal representation of a byte. 0x0f是一个字节的十六进制表示。 Specifically, the bit pattern 00001111具体来说,位模式00001111

It's taking the value of the character, shifting it 4 places to the right ( >>> 4 , it's an unsigned shift ) and then performing a bit-wise AND with the pattern above - eg ignoring the left-most 4 bits resulting in a number 0-15.它获取字符的值,将其向右移动 4 位( >>> 4 ,它是一个无符号移位),然后使用上面的模式执行按位AND - 例如忽略最左边的 4 位导致数字 0-15。

Then it adds that number to the original character's right-most 4 bits (the 2nd & 0x0F without a shift), another 0-15 number.然后它将该数字添加到原始字符最右边的 4 位(第二个& 0x0F没有移位),另一个 0-15 数字。

0x0F is a number in hexadecimal. 0x0F是十六进制数。 And >>> is the bitwise right-shift operator.>>>是按位右移运算符。

I have this code.我有这个代码。 Please make me understand what does this code actually mean请让我明白这段代码的实际含义

  for(var i = 0; i < input.length; i++)
  {
    x = input.charCodeAt(i);
    output += hex_tab.charAt((x >>> 4) & 0x0F)
           +  hex_tab.charAt( x        & 0x0F);
  }

What is 0x0F?什么是0x0F? And, >>> Mean?而且,>>>是什么意思?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM