如何在HTML5/javascript中查找十六进制值的特定位或数字?

如何在HTML5/javascript中查找十六进制值的特定位或数字?,javascript,html,hex,Javascript,Html,Hex,我想用十六进制编码很多东西。这里有一些例子 var LAST_DIGITS = 0x000000A7; // Last 2 digits represent something var MID_DIGITS = 0x00000E00; // 5th and 6th digits represent something else 假设我把最后的数字和中间的数字加在一起。这是0x00000EA7,代表我想要编码的两个不同的东西 有没有什么方法可以让我在javascript/HTML5中单独检查其

我想用十六进制编码很多东西。这里有一些例子

var LAST_DIGITS = 0x000000A7; // Last 2 digits represent something
var MID_DIGITS = 0x00000E00;  // 5th and 6th digits represent something else
假设我把最后的数字和中间的数字加在一起。这是0x00000EA7,代表我想要编码的两个不同的东西

有没有什么方法可以让我在javascript/HTML5中单独检查其中的一个子集?或者我必须将其转换为字符串或其他集合,然后显式引用索引吗

在上面的例子中,这里是我想要的

function getThemDigits (inHexValue) 
{
    // Check for 5th and 6th digits through my dream (not real!) function
    inHexValue.fakeGetHexValueFunction(4,5); // returns 0E

    // Check for last two digits for something else
    inHexValue.fakeGetHexValueFunction(6,7); // returns A7
}
公共位运算符(
|&>>
function GetHex(hex, offset) {
    // Move the two hex-digits to the very right (1 hex = 4 bit)
    var aligned = hex >> (4 * offset);

    // Strip away the stuff that might still be to the left of the
    // targeted bits:
    var stripped = aligned & 0xFF;

    // Transform the integer to a string (in hex representation)
    var result = stripped.toString(16);

    // Add an extra zero to ensure that the result will always be two chars long
    if (result.length < 2) {
        result = "0" + result;
    }

    // Return as uppercase, for cosmetic reasons
    return result.toUpperCase();
}
var LAST_DIGITS = 0x000000A7;
var MID_DIGITS = 0x00000E00;

var a = GetHex(LAST_DIGITS, 0);
var b = GetHex(MID_DIGITS, 2); // offset of 2 hex-digits, looking from the right