
write a menu driven program to accept a number belonging to any number system that is octal,binary,decimal,hexadecimal according to user's choice and display its equivalent number system entered according to the user's choice

Hi Friend,
Try the following code:
<html>
<script>
function getNumber(){
var num=document.getElementById('num').value;
var type=document.getElementById('type').value;
var sel=window.prompt("Select Number System:\n1 for Octal\n2 for Binary\n3 for Decimal\n4 for Hexadeciaml");
sel=parseInt(sel);
switch(sel){
case 1:
if(type=="decimal"){
num=parseInt(num);
var octal = num.toString(8);
alert(octal);
}
else if(type=="octal"){
alert("Entered value is in octal!");
}
else if(type=="hexadecimal"){
var number=parseInt(num,16);
alert(number.toString(8));
}
else if(type=="binary"){
var number=parseInt(num,2);
alert(number.toString(8));
}
break;
case 2:
if(type=="decimal"){
num=parseInt(num);
var binary = num.toString(2);
alert(binary);
}
else if(type=="octal"){
var number=parseInt(num,8);
alert(number.toString(2));
}
else if(type=="hexadecimal"){
var number=parseInt(num,16);
alert(number.toString(2));
}
else if(type=="binary"){
alert("Entered values is in binary!");
}
break;
case 3:
if(type=="decimal"){
alert("Entered value is in decimal!");
}
else if(type=="octal"){
var number=parseInt(num,8);
alert(number);
}
else if(type=="hexadecimal"){
var number=parseInt(num,16);
alert(number);
}
else if(type=="binary"){
var number=parseInt(num,2);
alert(number);
}
break;
case 4:
if(type=="decimal"){
num=parseInt(num);
var hexadecimal = num.toString(16);
alert(hexadecimal);
}
else if(type=="octal"){
var number=parseInt(num,8);
alert(number.toString(16));
}
else if(type=="hexadecimal"){
alert("Entered value is in hexadecimal!");
}
else if(type=="binary"){
var number=parseInt(num,2);
alert(number.toString(16));
}
break;
default:
}
}
</script>
Enter Number <input type="text" id="num"><br><br>
Enter Type <input type="text" id="type"><sub>binary,octal,decimal,hexadecimal</sub><br><br>
<input type="button" onclick="getNumber();" value="Get">
</html>
Thanks