9 examples of 'javascript int to binary' in JavaScript

Every line of 'javascript int to binary' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
21function binaryToByte(bin) {
22 return parseInt(bin, 2);
23}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

195arrayBufferToBinary(t) {
196 let e = '';
197 const n = new Uint8Array(t),
198 r = n.byteLength;
199 for (let t = 0; t < r; t++) e += String.fromCharCode(n[t]);
200 return e;
201}
103function binaryToDecimal(data) {
104 var ret = "";
105 while (data !== "0") {
106 var end = 0;
107 var fullName = "";
108 var i = 0;
109 for (; i < data.length; i++) {
110 end = 2 * end + parseInt(data[i], 10);
111 if (end >= 10) {
112 fullName += "1";
113 end -= 10;
114 } else {
115 fullName += "0";
116 }
117 }
118 ret = end.toString() + ret;
119 data = fullName.slice(fullName.indexOf("1"));
120 }
121 return ret;
122}
159function toBinaryArray(value, length) {
160 const binText = value.toString(2);
161 const result = new Array(length).fill(0n);
162 for (let i = binText.length - 1, j = 0; i >= 0; i--, j++) {
163 result[j] = BigInt(binText[i]);
164 }
165 return result;
166}
102function bin(value) {
103 return typeof value === 'string' ? parseInt(value, 2) : value;
104}
24function bytesToBinary(bytes) {
25 return bytes.map(x => lpad(x.toString(2), '0', 8)).join('');
26}
54function fromValueToBinary(value, convertFrom) {
55 var data;
56 if (data = bytes[convertFrom]) {
57 data.type[0] = value;
58 return byte.slice(0, data.size)
59 } else {
60 throw new Error("Invalid convert string")
61 }
62}
39export function binToInt(input: number[]): number {
40 return input.reduce(function(acc, val) {
41 return acc * 2 + val;
42 }, 0);
43}
44function convertToBinaryString(data) {
45 if(!data) {
46 return;
47 }
48 let binary = "";
49 const bytes = new Uint8Array(data);
50 for (var i = 0; i < bytes.byteLength; i++) {
51 binary += String.fromCharCode(bytes[i]);
52 }
53 return binary;
54}

Related snippets