2017-04-18 22:31:31 +02:00
|
|
|
// Copyright (C) 2017 André Bargull. All rights reserved.
|
|
|
|
// This code is governed by the BSD license found in the LICENSE file.
|
2017-07-14 17:37:24 +02:00
|
|
|
/*---
|
|
|
|
description: |
|
|
|
|
Collection of functions used to assert the correctness of various encoding operations.
|
2019-09-25 02:22:26 +02:00
|
|
|
defines: [decimalToHexString, decimalToPercentHexString]
|
2017-07-14 17:37:24 +02:00
|
|
|
---*/
|
2017-04-18 22:31:31 +02:00
|
|
|
|
|
|
|
function decimalToHexString(n) {
|
|
|
|
var hex = "0123456789ABCDEF";
|
|
|
|
n >>>= 0;
|
|
|
|
var s = "";
|
|
|
|
while (n) {
|
|
|
|
s = hex[n & 0xf] + s;
|
|
|
|
n >>>= 4;
|
|
|
|
}
|
|
|
|
while (s.length < 4) {
|
|
|
|
s = "0" + s;
|
|
|
|
}
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
function decimalToPercentHexString(n) {
|
|
|
|
var hex = "0123456789ABCDEF";
|
|
|
|
return "%" + hex[(n >> 4) & 0xf] + hex[n & 0xf];
|
|
|
|
}
|