25.09.2026 - fixed bug in binary calculator!
This commit is contained in:
Generated
+10
@@ -0,0 +1,10 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
# Ignored default folder with query files
|
||||
/queries/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
||||
Generated
+8
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="WEB_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
Generated
+8
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/2aAPC.iml" filepath="$PROJECT_DIR$/.idea/2aAPC.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
Generated
+19
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="MessDetectorOptionsConfiguration">
|
||||
<option name="transferred" value="true" />
|
||||
</component>
|
||||
<component name="PHPCSFixerOptionsConfiguration">
|
||||
<option name="transferred" value="true" />
|
||||
</component>
|
||||
<component name="PHPCodeSnifferOptionsConfiguration">
|
||||
<option name="highlightLevel" value="WARNING" />
|
||||
<option name="transferred" value="true" />
|
||||
</component>
|
||||
<component name="PhpStanOptionsConfiguration">
|
||||
<option name="transferred" value="true" />
|
||||
</component>
|
||||
<component name="PsalmOptionsConfiguration">
|
||||
<option name="transferred" value="true" />
|
||||
</component>
|
||||
</project>
|
||||
Generated
+6
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
@@ -126,9 +126,9 @@ function tryParseInt(str) {
|
||||
function flipBinString(remainderString)
|
||||
{
|
||||
let count = remainderString.length;
|
||||
let remainders = [count];
|
||||
let remainders = [];
|
||||
|
||||
for(i = 0; i < count; i++)
|
||||
for(let i = 0; i < count; i++)
|
||||
{
|
||||
remainders[i] = remainderString[i];
|
||||
}
|
||||
@@ -143,14 +143,26 @@ function additionTwoBinNumbers(bin1, bin2)
|
||||
let bin1Array = binArrays.first;
|
||||
let bin2Array = binArrays.second;
|
||||
let binOverflow = Array.from({length: bin2Array.length}, (v, k) => '0');
|
||||
let lastOverflowBit = '0';
|
||||
|
||||
let tempResult = "";
|
||||
|
||||
for(i = bin1Array.length-1; i >= 0; i--){
|
||||
|
||||
if(bin1Array[i] === '0' && bin2Array[i] === '0' && binOverflow[i] === '0')
|
||||
function setOverflow(index){
|
||||
if(isLastIndex(index))
|
||||
{
|
||||
lastOverflowBit = '1';
|
||||
}else{
|
||||
binOverflow[index-1] = '1';
|
||||
}
|
||||
}
|
||||
|
||||
for(let i = bin1Array.length-1; i >= 0; i--){
|
||||
|
||||
if(bin1Array[i] === '0' && bin2Array[i] === '0' && binOverflow[i] === '0') {
|
||||
tempResult += '0';
|
||||
}else if(bin1Array[i] === '0' && bin2Array[i] === '0' && binOverflow[i] === '1')
|
||||
{
|
||||
tempResult += '1';
|
||||
}else if (((bin1Array[i] === '0' && bin2Array[i] === '1') || (bin1Array[i] === '1' && bin2Array[i] === '0')) && binOverflow[i] === '0')
|
||||
{
|
||||
tempResult += '1';
|
||||
@@ -158,20 +170,20 @@ function additionTwoBinNumbers(bin1, bin2)
|
||||
else if (((bin1Array[i] === '0' && bin2Array[i] === '1') || (bin1Array[i] === '1' && bin2Array[i] === '0')) && binOverflow[i] === '1')
|
||||
{
|
||||
tempResult += '0';
|
||||
binOverflow[i-1] = '1';
|
||||
setOverflow(i);
|
||||
}
|
||||
else if((bin1Array[i] === '1' && bin2Array[i] === '1') && binOverflow[i] === '0')
|
||||
{
|
||||
tempResult += '0';
|
||||
binOverflow[i-1] = '1';
|
||||
setOverflow(i);
|
||||
}else if((bin1Array[i] === '1' && bin2Array[i] === '1') && binOverflow[i] === '1')
|
||||
{
|
||||
tempResult += '1';
|
||||
binOverflow[i-1] = '1';
|
||||
setOverflow(i);
|
||||
}
|
||||
}
|
||||
|
||||
if(binOverflow[-1] === '1')
|
||||
if(lastOverflowBit === '1')
|
||||
{
|
||||
tempResult += '1';
|
||||
}
|
||||
@@ -180,6 +192,10 @@ function additionTwoBinNumbers(bin1, bin2)
|
||||
return tempResult;
|
||||
}
|
||||
|
||||
function isLastIndex(index){
|
||||
return index === 0;
|
||||
}
|
||||
|
||||
function fillwithZero(binArray1, binArray2)
|
||||
{
|
||||
let difference = Math.abs(binArray1.length - binArray2.length);
|
||||
@@ -188,14 +204,14 @@ function fillwithZero(binArray1, binArray2)
|
||||
{
|
||||
if(binArray1.length < binArray2.length)
|
||||
{
|
||||
for(i = 0; i < difference; i++)
|
||||
for(let i = 0; i < difference; i++)
|
||||
{
|
||||
binArray1.unshift('0');
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for(i = 0; i < difference; i++)
|
||||
for(let i = 0; i < difference; i++)
|
||||
{
|
||||
binArray2.unshift('0');
|
||||
}
|
||||
@@ -205,5 +221,4 @@ function fillwithZero(binArray1, binArray2)
|
||||
first: binArray1,
|
||||
second: binArray2
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user