binaryMultiplication function
Implementation
String binaryMultiplication({
///Number to multiply
required String binaryNumber,
///Times it will be multiplied by
required String times,
}){
String result = "";
for(int i = times.length - 1; 0 <= i; i--){
String thisStepsResult = "";
String bin1 = times.substring(i,i+1);
int parsedBin1 = int.parse(bin1);
//Add the necessary zeroes to the right of the number
for(int p = 0; p <= i; p++){
thisStepsResult += "0";
}
//Multiply
for(int e = binaryNumber.length - 1; 0 <= e; e--){
String bin2 = binaryNumber.substring(e,e+1);
int parsedBin2 = int.parse(bin2);
//print("$parsedBin1 * $parsedBin2 = ${parsedBin1 * parsedBin2}");
if(parsedBin1 * parsedBin2 == 1){
thisStepsResult = "1$thisStepsResult";
}else{
thisStepsResult = "0$thisStepsResult";
}
}
//print(thisStepsResult);
//Add the result
result = binaryAddition(
binaryNumber1: result,
binaryNumber2: thisStepsResult,
);
}
//Remove unecessary zeroes
if(result.startsWith("0") && result.length > 1){
result = result.substring(1);
}
return result;
}