JSFiddle - React, Tailwind, and code Playground
by cubicalmonkey
HTML
<script>alert( nBit2Dec('1111100000000000', '16') )</script>
JavaScript
function bindechexMain() {
this.version = '0.78';
w = 500;
this.binTypes = [
'number',
'0001',
'signed 8-bit',
'signed 16-bit',
'signed 32-bit'
];
var s = '';
s += '<div style="position: relative; max-width: ' + w + 'px; margin: auto; border-radius: 10px; background-color: #ddeeff;">';
s += '<div style="text-align: center; padding:6px;">';
s += 'Binary type: ';
this.binTypes = [
'number',
'0001',
'signed 8-bit',
'signed 16-bit',
'signed 32-bit'
];
s += getDropdownHTML(this.binTypes, 'go(-1)', 'bintype');
s += '</div>';
this.flds = [
['Binary',
'blue'],
[
'Decimal',
'darkblue'
],
[
'Hexadecimal',
'green'
]
];
s += '<div style="line-height: 32px;">';
for (var i = 0; i < 3; i++) {
s += '<div style="width: 120px; float:left; text-align: right; vertical-align: top; ">';
s += '<span style="font: bold 16px Arial; color: ' + this.flds[i][1] + '; ">' + this.flds[i][0] + ': </span>';
s += '</div>';
s += '<div style="overflow:hidden; width:auto;text-align: left; ">';
s += '<textarea id="text' + i + '" style="width: 90%; height: 52px; text-align: center; border-radius: 10px; font: 18px Arial; color: #0000ff; color: ' + this.flds[i][1] + '; background-color: #eeffee; " value="" onKeyUp="go(' + i + ')"></textarea>';
if (i == 1) {
s += '<div style="display: inline-block; width: 6%;">';
s += '<button onclick="numAdd(1)" style="font: 22px Arial;" class="togglebtn" >+</button>';
s += '<button onclick="numAdd(-1)" style="font: 22px Arial;" class="togglebtn" >−</button>';
s += '</div>';
}
s += '</div>';
}
s += '</div>';
s += '<div style="line-height: 20px;"> </div>';
s += '<div id="copyrt" style="position: absolute; left: 5px; bottom: 3px; font: 10px Arial; color: #6600cc; ">© 2017 MathsIsFun.com v' + this.version + '</div>';
s += '</div>';
document.write(s);
...