Extended Brain Storage

JavaScript: Base Conversion

Posted on November 13, 2012

Smooth and sound base conversion between hex and dec (hex2dec and dec2hex)...

Source Code

JavaScript code:

function dec2hex(){
dec = document.getElementById('decsrc').value;
res = parseInt(dec).toString(16);
document.getElementById('hexres').value = res;
}

function hex2dec(){
hex = document.getElementById('hexsrc').value;
res = parseInt(hex, 16);
document.getElementById('decres').value = res;
}

HTML code:

DEC:<input type="text" id="decsrc" oninput="dec2hex();" />
HEX:<input type="text" id="hexres" />
HEX:<input type="text" id="hexsrc" oninput="hex2dec();" />
DEC:<input type="text" id="decres" />

Tags: #JavaScript #base #conversion

⏴ Previous Post Next Post ⏵