shell.js (698B)
1 // GENERATED, DO NOT EDIT 2 // file: decimalToHexString.js 3 // Copyright (C) 2017 André Bargull. All rights reserved. 4 // This code is governed by the BSD license found in the LICENSE file. 5 /*--- 6 description: | 7 Collection of functions used to assert the correctness of various encoding operations. 8 defines: [decimalToHexString, decimalToPercentHexString] 9 ---*/ 10 11 function decimalToHexString(n) { 12 var hex = "0123456789ABCDEF"; 13 n >>>= 0; 14 var s = ""; 15 while (n) { 16 s = hex[n & 0xf] + s; 17 n >>>= 4; 18 } 19 while (s.length < 4) { 20 s = "0" + s; 21 } 22 return s; 23 } 24 25 function decimalToPercentHexString(n) { 26 var hex = "0123456789ABCDEF"; 27 return "%" + hex[(n >> 4) & 0xf] + hex[n & 0xf]; 28 }