-
Notifications
You must be signed in to change notification settings - Fork 3
/
test1.html
58 lines (49 loc) · 1.43 KB
/
test1.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script type="module">
let bases = "{id:6}"
// 字符串转字节
// let temp1 = s2b(bases)
// console.log(new Uint8Array(temp1))
// byte转字符串
function b2s(bytes) {
let str = []
for (let i in bytes) {
str.push(String.fromCharCode(bytes[i]))
}
return str.join("")
}
function s2b(str) {
let bytes = []
for (let i in str) {
bytes.push(str.charCodeAt(i) & 0xFF)
}
return bytes
}
let basedata = new Uint8Array(new ArrayBuffer(30000 / 8))
let setData = (key, value) => {
let index = Math.floor(key / 8)
const dex = key % 8
const byte = value.charCodeAt(0) & 0xFF
console.log(byte)
basedata[index] = byte ^ (2 ** dex)
}
setData(5, "2")
// 获取 序号状态
function getStatus(id) {
const index = Math.floor(id / 8)
const dex = id % 8
const byte = basedata[index]
return (byte & (2 ** dex))
}
getStatus(5)
</script>
</body>
</html>