I found some code that fits my needs :
var hexes = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'];
var min = min || 2;
var nibble;
var outHex='';
do{
nibble = inNumber & 0x0f;
inNumber = inNumber >> 4;
outHex = hexes[nibble] + outHex;
}while( inNumber );
if( outHex.length < min )
{
outHex = new Array(min-outHex.length+1).join('0') + outHex;
}