We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 060ee86 commit 0c79609Copy full SHA for 0c79609
Bit-Manipulation/HammingCode.js
@@ -0,0 +1,29 @@
1
+/**
2
+ * github author: chrdek
3
+ * license: GPL-3.0 or later
4
+ *
5
+ * @param {number} b
6
7
+ * The following code generates the hamming code for
8
+ * 32-bit integer values (incl. parity bit check)
9
10
+ **/
11
+
12
+function HammingCode(b) {
13
+ var bytes = new Array(65536);
14
+ const bitAlloc = (bin) => {
15
+ var cnt = 0;
16
+ while (bin > 0) {
17
+ cnt += bin & 1;
18
+ bin >>=1;
19
+ }
20
+ return cnt;
21
+ } //end of bitallocation
22
23
+for (var k=0; k < 65536; k++) bytes[k] = bitAlloc(k);
24
25
+//perform leftmost shifting for integer value
26
+return bytes[b & 0xFFFF] + bytes[b >> 16];
27
+}
28
29
+export { HammingCode }
0 commit comments