<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin
function NumToHex(num1,num2) {
strNum=document.forms[0].elements[num1].value;
for(i = 0; i < strNum.length; i++) {
chr=strNum.substring(i, i + 1);		
if((isNaN(chr))||(chr == ' ')) {
alert('You must enter a digit between 0 and 9!');
document.forms[0].elements[num1].select();
document.forms[0].elements[num2].value='';
return false;
   }
}
if(strNum > 255) {
alert('You must enter a number between 0 and 255!');
document.forms[0].elements[num1].select();
document.forms[0].elements[num2].value='';
return false;
}
else {
base = strNum / 16;
rem = strNum % 16;
base = base - (rem / 16);
baseS = MakeHex(base);
remS = MakeHex(rem);
document.forms[0].elements[num2].value=baseS + '' + remS;
return true;
   }
}
function MakeHex(x) {
if((x >= 0) && (x <= 9))
return x;
else {
switch(x) {
case 10: return "A"; 
case 11: return "B";  
case 12: return "C";  
case 13: return "D";  
case 14: return "E";  
case 15: return "F";  
      }
   }
}
function HexToNum(num1,num2) {
numberS = document.forms[0].elements[num1].value;
tens = MakeNum(numberS.substring(0,1));
if(tens == 'X') {
document.forms[0].elements[num1].select();
document.forms[0].elements[num2].value='';
return false;
}
ones = 0;
if(numberS.length > 1) // means two characters entered
ones=MakeNum(numberS.substring(1,2));
if(ones == 'X') {
document.forms[0].elements[num1].select();
document.forms[0].elements[num2].value='';
return false;
}
document.forms[0].elements[num2].value = (tens * 16) + (ones * 1);
document.forms[0].elements[num1].value = document.forms[0].elements[num1].value.toUpperCase();
return true;
}
function MakeNum(str) {
if((str >= 0) && (str <= 9))
return str;
switch(str.toUpperCase()) {
case "A": return 10;
case "B": return 11;
case "C": return 12;
case "D": return 13;
case "E": return 14;
case "F": return 15;
default:  alert('You must choose a number between 0 and 9 or a letter between A and F!');
return 'X';
   }
} 
//  End -->
