-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbaseTen2base2Conv.js
More file actions
30 lines (30 loc) · 1.02 KB
/
baseTen2base2Conv.js
File metadata and controls
30 lines (30 loc) · 1.02 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
// Created by John Nieves on 1/8/2015.
function int32ToIp(int32){
//binInt represents incomplete binary conversion
binInt = "";
while (int32 >= 1) {
//console.log(Math.sqrt(int32));
int32 = int32 / 2;
console.log(int32);
if (int32 % 1 >= .5) {
binInt += "1";
} else if (int32 % 1 < .5) {
binInt += "0";
}
}
console.log(binInt);
// below is DEFINITELY not working yet.
var tempStr, int8 = 0;
for (var i = 0; i < binInt.length; i+=8) {
tempStr = binInt.substring(i, i+8); // extract chunk in 8bit segments
// reverse chunk for calculation from left to right
// actually .. may not need to do this, can count chars and just iterate downward instead of up from initial.
for (var j = 0; j < tempStr.length; j++) {
// need to build out binary to 8 bit address converter
int8 += Math.pow(2, j) * Number(tempStr.charAt(j));
}
}
return int8;
}
var int32 = 1000;
console.log(int32ToIp(int32));