Permalink
Browse files

Optimized hex16 and hex32 functions.

  • Loading branch information...
Alex Gorbatchev Alex Gorbatchev
Alex Gorbatchev authored and Alex Gorbatchev committed Dec 7, 2010
1 parent 7b9146d commit d2bdb13f65eb1bbaee1def16b5caf1fe83083da8
Showing with 2 additions and 21 deletions.
  1. +2 −21 lib/crc.js
View
@@ -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 {

0 comments on commit d2bdb13

Please sign in to comment.