25.09.2026 - 4 - BUG in binCalc?

This commit is contained in:
2026-09-25 12:53:30 +02:00
parent 881dfec7fa
commit 5cdadd4e49
+26 -25
View File
@@ -3,21 +3,21 @@ function setSize(varWidth, varHeight){
let boxHeight = (varHeight / 2); let boxHeight = (varHeight / 2);
let boxWidth = (varWidth / 2); let boxWidth = (varWidth / 2);
if((boxHeight >= 300) && (boxWidth >= 300)) if((boxHeight >= 300) && (boxWidth >= 300))
{ {
box.style.backgroundColor = 'red'; box.style.backgroundColor = 'red';
}else{ }else{
box.style.backgroundColor = 'yellow'; box.style.backgroundColor = 'yellow';
} }
box.style.width = boxWidth+'px'; box.style.width = boxWidth+'px';
box.style.height = boxHeight+'px'; box.style.height = boxHeight+'px';
let textInBox = document.getElementsByClassName('boxTextClass')[0]; let textInBox = document.getElementsByClassName('boxTextClass')[0];
textInBox.style.color = 'blue'; textInBox.style.color = 'blue';
textInBox.style.margin = '25%'; textInBox.style.margin = '25%';
textInBox.style.marginLeft = '25%'; textInBox.style.marginLeft = '25%';
} }
@@ -83,10 +83,11 @@ document.getElementById("startBinCalc").addEventListener('click', function(){
let bin1 = calcDezToBin(dezNumberToBin1); let bin1 = calcDezToBin(dezNumberToBin1);
let bin2 = calcDezToBin(dezNumberToBin2); let bin2 = calcDezToBin(dezNumberToBin2);
let numbersForText = fillwithZero(bin1.split(''), bin2.split(''));
let result = additionTwoBinNumbers(bin1, bin2); let result = additionTwoBinNumbers(bin1, bin2);
//let numbersForText = fillwithZero(bin1, bin2);
document.getElementById('binCalcResult').innerText = bin1 + " + " + bin2 + " = " + result;
document.getElementById('binCalcResult').innerHTML = "<center>&nbsp;&nbsp; "+numbersForText.first.join('') + "<br>+ " + numbersForText.second.join('') + "<br>&nbsp;&nbsp; " + result+" </center>";
} }
}); });
@@ -110,16 +111,16 @@ function calcDezToBin(dezNumber){
} }
function tryParseInt(str) { function tryParseInt(str) {
let retValue = null; let retValue = null;
if(str !== null) { if(str !== null) {
if(str.length > 0) { if(str.length > 0) {
if (!isNaN(str)) { if (!isNaN(str)) {
retValue = parseInt(str); retValue = parseInt(str);
return retValue; return retValue;
} }
} }
} }
return str; return str;
} }
function flipBinString(remainderString) function flipBinString(remainderString)
@@ -138,12 +139,12 @@ function flipBinString(remainderString)
function additionTwoBinNumbers(bin1, bin2) function additionTwoBinNumbers(bin1, bin2)
{ {
let binArrays = fillwithZero(bin1.split(""), bin2.split("")); let binArrays = fillwithZero(bin1.split(''), bin2.split(''));
let bin1Array = binArrays.first; let bin1Array = binArrays.first;
let bin2Array = binArrays.second; let bin2Array = binArrays.second;
let binOverflow = Array.from({length: bin2Array.length}, (v, k) => '0'); let binOverflow = Array.from({length: bin2Array.length}, (v, k) => '0');
let tempResult = "" let tempResult = "";
for(i = bin1Array.length-1; i >= 0; i--){ for(i = bin1Array.length-1; i >= 0; i--){