Convert an array of big-endian words to a hex string. - Node.js String

Node.js examples for String:Big endian

Description

Convert an array of big-endian words to a hex string.

Demo Code

var hexcase = 0;/*from   w ww .ja v a2  s. c  o  m*/


function binb2hex(binarray) {
  var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef";
  var str = "";
  for (var i = 0; i < binarray.length * 4; i++) {
    str += hex_tab.charAt((binarray[i >> 2] >> ((3 - i % 4) * 8 + 4)) & 0xF) +
      hex_tab.charAt((binarray[i >> 2] >> ((3 - i % 4) * 8  )) & 0xF);
  }
  return str;
}

Related Tutorials