-
Notifications
You must be signed in to change notification settings - Fork 0
/
ip.html
104 lines (90 loc) · 1.5 KB
/
ip.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<!DOCTYPE html>
<html>
<head>
<title>binary Calculater</title>
<script type="text/javascript">
var c="";
function count()
{
str=t1.value;
arr=str.split(".")
for(i=0;i<arr.length;i++)
{ s=bin(Number(arr[i]));
c=c+s;
}
t.value=c;
}
function bin(str)
{
r="";
while(str>0)
{
r=r+String(str%2);
str=Math.floor(str/2);
}
i=r.length;
s="";
for(j=i-1;j>=0;j--)
{
s=s+r[j];
}
while(s.length<8)
s='0'+s
return s;
}
function octal()
{
r="";
str=Number(t1.value);
while(str>0)
{
r=r+String(str%8);
str=Math.floor(str/8);
}
i=r.length;
s="";
for(j=i-1;j>=0;j--)
{
s=s+r[j];
}
t.value=s;
}
function decimal()
{
i=0;
sum=0;
str=Number(t.value);
while(str>0)
{
r=str%10;
str=Math.floor(str/10);
sum=sum+(r*Math.pow(2,i));
i++;
}
t1.value=sum;
}
function octalTodecimal()
{
i=0;
sum=0;
str=Number(t.value);
while(str>0)
{
r=str%10;
str=Math.floor(str/10);
sum=sum+(r*Math.pow(8,i));
i++;
}
t1.value=sum;
}
</script>
</head>
<body>
<h3>Enter Decimal Number:</h3>
<input type="text" name="t1" id="t1"/><br>
<h3>Binary:</h3>
<input type="text" name="t" id="t"/><br>
<input type="button" onclick="count()" value="binary">
<input type="button" onclick="decimal()" value="Decimal">
</body>
</html>