我的方法是获取两个BCD,它们是从驱动程序构造的整数,并将它们相乘:
public BCD multiplyBCDs(BCD other){ //to multiply two BCDs together
BCD basebcd = new BCD(digit);
BCD otherbasebcd = other;
int base = 0;
for(int y = 0; y<basebcd.numberOfDigits();y++){
base += digit[y];
int g = y;
while(g < basebcd.numberOfDigits()){
digit[g]*=10;
g++;
}
}
int baser = 0;
if(otherbasebcd.numberOfDigits() >= basebcd.numberOfDigits()){
for(int v = 0; v < otherbasebcd.numberOfDigits(); v++){
baser += base*otherbasebcd.nthDigit(v);
int j = v;
while(j < other.numberOfDigits()){
byten(otherbasebcd.nthDigit(j));
j++;
}
}
}
else{
for(int v = 0; v < basebcd.numberOfDigits(); v++){
baser += base*otherbasebcd.nthDigit(v);
int j = v;
while(j < other.numberOfDigits()){
byten(otherbasebcd.nthDigit(j));
j++;
}
}
}
BCD newBCD = new BCD(baser);
return newBCD;
}byten方法假设将每个数字的"other“乘以10,得到一个类似838的数字,而不是8+3+8。但是如果我输入数字10和12,该方法将添加10*1和10*2,结果是30而不是120。有什么建议吗?
十个字节:
public int byten(int j){
j*=10;
return j;
}发布于 2015-11-30 03:48:45
将输入更改为整数
int a= Integer.parseInt(basebcd.toString(), 2);
int b = Integer.parseInt(otherbasebcd.toString(), 2);使用两个int进行运算
res = i*j;转换为BCD
String s = Integer.toBinaryString(res);https://stackoverflow.com/questions/33986747
复制相似问题