开发者

Javascript Question: How to Convert Hexadecimal Number to High and Low 32-bit values

I need a few lines of Javascript code that will take a hexadecimal number (in the form of a 16 character string) and convert it to two variables representing the high and low 32 bits of the 64-bit original value.

I am trying to use the iTunes COM function "ItemByPersistenID" to play a song in iTunes with Windows Script. But I only have the hexadecimal value of the PersistentId and the function only takes the high and low 32-bits.

The function definition (from the开发者_JAVA百科 iTunes COM SDK documentation)

function TrackCollection:ItemByPersistentId(long highID, long lowID)

where the "highID" parameter is "The high 32 bits of the 64-bit persistent ID" and "lowID" is "The low 32 bits of the 64-bit persistent ID".


Try

var loNibble = parseInt( hexValue.substring(8,16) , 16 ) ;
var hiNibble = parseInt( hexValue.substring(0,8)  , 16 ) ;


Nicholas has a good answer. In the hypothetical case that the hex string doesn't have leading zeroes you could do:

var a=hexstr.match(/(.*?)(.{0,8})$/);
var lo=parseInt(a[2],16);
var hi=parseInt(a[1],16);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜