-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathutilities.ts
34 lines (24 loc) · 890 Bytes
/
utilities.ts
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
export default class Utilities {
static bytesToHexString(bytesArray : Array<number>) : string {
let atrHex : string = "";
if (bytesArray && bytesArray.length > 0)
bytesArray.map(val => {
if (val.toString(16).length == 1)
atrHex += "0";
atrHex += val.toString(16);
});
return atrHex;
}
static hexStringToBytes(str: string): number[] {
if (!str) {
return [];
}
const numberArray: number[] = [];
for (let i: number = 0, len = str.length; i < len; i += 2) {
numberArray.push(parseInt(str.substr(i, 2), 16));
}
return numberArray;
}
static lowestByteFromShort = (short : number) => short & 0x00FF;
static highestByteFromShort = (short : number) => (short & 0xFF00) >> 8;
}