forked from FlipperMaker/flippermaker.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgeneral.js
More file actions
72 lines (69 loc) · 1.64 KB
/
general.js
File metadata and controls
72 lines (69 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
function cleanString(inputString) {
return inputString.toString().replace(/\s/g, "");
}
function replaceSpace(inputString, replacement) {
return inputString.toString().replace(/\s/g, replacement);
}
function pad(num, size) {
num = cleanString(num);
while (num.length < size) num = "0" + num;
return num;
}
function intToHex(inputNumber) {
var hexString = parseInt(inputNumber, 10).toString(16);
return hexString.toString().toUpperCase();
}
function hexToInt(inputHex) {
var hexString = parseInt(inputHex, 16);
return hexString.toString();
}
function intToBin(inputNumber) {
var binString = parseInt(inputNumber, 10).toString(2);
return binString.toString();
}
function binToInt(inputBin) {
var binString = parseInt(inputBin, 2);
return binString.toString();
}
function binToHex(inputBin) {
return intToHex(binToInt(inputBin)).toUpperCase();
}
function hexToBin(inputHex) {
return intToBin(hexToInt(inputHex));
}
function findParity(parity, bin) {
const arr = bin.toString().split("");
let countOnes = 0;
let res = 0;
for (let i = 0; i < arr.length; i++) {
if (arr[i] == 1) {
countOnes += 1;
}
}
if (parity == "even") {
if (countOnes % 2 == 0) {
res = 0;
} else {
res = 1;
}
} else {
if (countOnes % 2 !== 0) {
res = 0;
} else {
res = 1;
}
}
return res;
}
function allNumeric(inputText) {
return /^\d+$/.test(inputText);
}
function allAlphaNumericUnderscore(inputText) {
return /^[A-Za-z_0-9]+$/.test(inputText);
}
function allBinary(inputText) {
return /^[0-1]+$/.test(inputText);
}
function splitIntoPairs(inputString) {
return inputString.match(/(..?)/g);
}