Skip to content

Commit

Permalink
Optimized hex16 and hex32 functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Gorbatchev authored and Alex Gorbatchev committed Dec 7, 2010
1 parent 7b9146d commit d2bdb13
Showing 1 changed file with 2 additions and 21 deletions.
23 changes: 2 additions & 21 deletions lib/crc.js
Expand Up @@ -328,34 +328,15 @@ define([], function()
*/
function hex16(val)
{
var n=val&0xFFFF;
var str=n.toString(16).toUpperCase();
while (str.length<4)
{
str="0"+str;
}
return str;
return hex8(val >> 8) + hex8(val);
}

/**
* Convert value as 32-bit unsigned integer to 8 digit hexadecimal number.
*/
function hex32(val)
{
var str2;
var n=val&0xFFFF;
var str1=n.toString(16).toUpperCase();
while (str1.length<4)
{
str1="0"+str1;
}
n=(val>>>16)&0xFFFF;
str2=n.toString(16).toUpperCase();
while (str2.length<4)
{
str2="0"+str2;
}
return str2+str1;
return hex16(val >> 16) + hex16(val);
}

return {
Expand Down

0 comments on commit d2bdb13

Please sign in to comment.