我想知道如何用->交换十六进制值的字节顺序(例如:4075javascript 7540,3827javascript 2738),如果是这样的话,如何交换?谢谢。
编辑:谢谢@kay,我想做的是交换十六进制的字节顺序。
发布于 2011-10-31 00:30:26
交换数字v的字节顺序
var v = 0x01234567; // input number
var s = v.toString(16); // translate to hexadecimal notation
s = s.replace(/^(.(..)*)$/, "0$1"); // add a leading zero if needed
var a = s.match(/../g); // split number in groups of two
a.reverse(); // reverse the groups
var s2 = a.join(""); // join the groups back together
var v2 = parseInt(s2, 16); // convert to a number
alert(s2); // "67452301"
alert(v2); // 1732584193Live copy
在一个长长的队伍中:
alert(parseInt((0x01234567).toString(16).replace(/^(.(..)*)$/, "0$1").match(/../g).reverse().join(""), 16))https://stackoverflow.com/questions/7946094
复制相似问题