LukeHan 의 잡다한 기술 블로그

byte to hex, number to hex, hex to number, character to ascii, uint16 to ascii 본문

개발/javascript

byte to hex, number to hex, hex to number, character to ascii, uint16 to ascii

LukeHan1128 2023. 4. 30. 20:00
반응형

 

// byte to hex
function toHexString(byteArray){
    return Array.from(byteArray, function(byte){
            return ('0' + (byte & 0xFF).toString(16)).slice(-2);
        }).join('')
}

 

 

// number to hex
function dec2hex(num){
    hexString = num.toString(16);
    return hexString;
}

 

 

// hex to number
function hex2dec(hexString){
    num = parseInt(hexString, 16);
    return num;
}

 

 

// char to ascii
function char2ascii(numStr){
    return numStr.charCodeAt(0);
}

 

 

// uint16 to ascii
var uInt16 = hex2dec(66);
var ascii = String.fromCharCode(uInt16).toUpperCase();
console.log(ascii);

/****** print : F ******/

 

 

 

반응형
Comments