Nodejs String to Hex Convert toHexString()

Here you can find the source of toHexString()

Method Source Code

String.prototype.toHexString = function()
{
   var res = [];/*from   www .  ja  v  a  2 s .c o  m*/
   for(var i=0, j=this.length; i < j; ++i)
   {
      var chr = this.charCodeAt(i).toString(16);

      chr = ((chr.length == 1)?'0':'') + chr;
      res.push(chr);
   }
   return res.join(' ').toUpperCase();
}

Related

  1. hex2Dec()
    String.prototype.hex2Dec = function() {
      return parseInt(this,16);
    };
    
  2. toHex()
    String.prototype.toHex = function () {
        var self = this,
            hex, regex = /\(([^)]+)\)/,
            rgb = regex.exec(self)[1].split(','),
            red = parseInt(rgb[0]), 
            green = parseInt(rgb[1]), 
            blue = parseInt(rgb[2]); 
        function toHEX(r, g, b) {
            r = r.toString(16).length ==1 ? r.toString(16)+r.toString(16):r.toString(16);
    ...
    
  3. toHex()
    String.prototype.toHex = function() {
      for (var i = 1, j = this.length, $ = this.charCodeAt(0).toString(16); i<j; i++) $ += ' ' + this.charCodeAt(i).toString(16);
      return $;
    };
    
  4. toHex(v1)
    Util.toHex = function(v1) {
      var res = (new Number(v1).toString(16));
      if (res.length == 1) {
        res = "0" + res;
      return res;
    
  5. toHexString()
    Number.prototype.toHexString = function() {
      if (this === null) { return null; }
      if (isNaN(this)) { return this; }
      var num;
      var hex;
      if (this < 0) {
        num = 0xFFFFFFFF + this + 1;
      else {
    ...