javascript String 转 bytes

实现String转bytes属性扩展

String.prototype.toBytes = function () {
     var ch, st, re = [];
     for (var i = 0; i < this.length; i++) {
         ch = this.charCodeAt(i);   // get char
         st = [];                   // set up "stack"
         do {
             st.push(ch & 0xFF);    // push byte to stack
             ch = ch >> 8;          // shift value down by 1 byte  
         }
         while (ch);
         // add stack contents to result  
         // done because chars have "wrong" endianness  
         re = re.concat(st.reverse());
     }
     // return an array of bytes  
     return re;
 }
—— 完 ——
相关推荐
评论

立 为 非 似

中 谁 昨 此

宵 风 夜 星

。 露 , 辰

文章点击榜

细 无 轻 自

如 边 似 在

愁 丝 梦 飞

。 雨 , 花