Convert value to hex - Node.js Number

Node.js examples for Number:Hex

Description

Convert value to hex

Demo Code

function toHex(n){
    n = parseInt(n, 10);/*from  w w  w  .j  ava  2  s .c o m*/
    if( isNaN(n) ) return '00';
    n = Math.max(0, Math.min(n, 255));
    return '0123456789ABCDEF'.charAt( (n-n%16) / 16 ) + '0123456789ABCDEF'.charAt(n%16);
}

Related Tutorials