OILS / benchmarks / javascript / hexstring.js View on Github | oilshell.org

45 lines, 36 significant
1#!/usr/bin/env node
2
3function main() {
4 var hexdigits = '0123456789abcdef'
5 for (var i = 0; i < 16; ++i) {
6 for (var j = 0; j < 16; ++j) {
7 for (var k = 0; k < 16; ++k) {
8 var hexbyte = hexdigits[i] + hexdigits[j] + hexdigits[k];
9
10 var byte = hexbyte;
11 // JS doesn't have replaceAll() for a fixed string
12 // https://stackoverflow.com/questions/5649403/how-to-use-replaceall-in-javascript
13 byte = byte.replace(/0/g, '0000')
14 byte = byte.replace(/1/g, '0001')
15 byte = byte.replace(/2/g, '0010')
16 byte = byte.replace(/3/g, '0011')
17
18 byte = byte.replace(/4/g, '0100')
19 byte = byte.replace(/5/g, '0101')
20 byte = byte.replace(/6/g, '0110')
21 byte = byte.replace(/7/g, '0111')
22
23 byte = byte.replace(/8/g, '1000')
24 byte = byte.replace(/9/g, '1001')
25 byte = byte.replace(/a/g, '1010')
26 byte = byte.replace(/b/g, '1011')
27
28 byte = byte.replace(/c/g, '1100')
29 byte = byte.replace(/d/g, '1101')
30 byte = byte.replace(/e/g, '1110')
31 byte = byte.replace(/f/g, '1111')
32
33 //print(byte)
34
35 ones = byte.replace(/0/g, '')
36 if (ones.length == 11) {
37 console.log(hexbyte, byte)
38 }
39 }
40 }
41 }
42}
43
44
45main()