没有合适的资源?快使用搜索试试~ 我知道了~
BOOTH算法定点一位乘实现。输入格式为带符号的小数真值中间用逗号隔开,注意输入法注意输入法,写的比较粗糙
资源推荐
资源详情
资源评论
//Booth实现定点补码一位乘,请直接输入被乘数与乘数的........带符号二进制纯小数形式..........!!!!记得要切换输入法
//输出是带符号的二进制纯小数
#include<iostream>
#include<string>
#include<cstdlib>
using namespace std;
int N = 0; //记录移位的次数
int Yn = 0;//附加位
void Comp(string value, char store[], int length);//求补码
void RMove(char *partproduct, char*X2, int partproduct_length, int X2_length);//右移操作,乘数移丢的位存放在Yn
void Minus(char X1[], char minus[], int X1_length);//求【-X】的补数
void Plus(char partproduct[], char X1[], char X2[], char minus[], int X1_length, int X2_length);//加法
void Multiply(char X1[], char X2[], char product[], char minus[], int X1_length, int X2_length);
void Comp2(char product[], char finalproduct[], int product_length);//将结果转换成真值
void main()
{
string muled, muler;
getline(cin, muled, ',');
getline(cin, muler, '\n');
int store1_length, store2_length, minus_length, product_length,
X1_length, X2_length, finalproduct_length;
//算出所用数组的长度,并开辟出数组空间
int i;
for (i = 0; muled[i] != NULL; i++);
store1_length = i;
int j;
//输出是带符号的二进制纯小数
#include<iostream>
#include<string>
#include<cstdlib>
using namespace std;
int N = 0; //记录移位的次数
int Yn = 0;//附加位
void Comp(string value, char store[], int length);//求补码
void RMove(char *partproduct, char*X2, int partproduct_length, int X2_length);//右移操作,乘数移丢的位存放在Yn
void Minus(char X1[], char minus[], int X1_length);//求【-X】的补数
void Plus(char partproduct[], char X1[], char X2[], char minus[], int X1_length, int X2_length);//加法
void Multiply(char X1[], char X2[], char product[], char minus[], int X1_length, int X2_length);
void Comp2(char product[], char finalproduct[], int product_length);//将结果转换成真值
void main()
{
string muled, muler;
getline(cin, muled, ',');
getline(cin, muler, '\n');
int store1_length, store2_length, minus_length, product_length,
X1_length, X2_length, finalproduct_length;
//算出所用数组的长度,并开辟出数组空间
int i;
for (i = 0; muled[i] != NULL; i++);
store1_length = i;
int j;
for (j = 0; muler[j] != NULL; j++);
store2_length = j;
char *store1 = new char[store1_length];//转换时暂存补码
char *store2 = new char[store2_length];
minus_length = store1_length + 1;
char *minus = new char[minus_length];//[-x]的补数
product_length = store1_length + store2_length - 3;
finalproduct_length = product_length + 1;
char *product = new char[product_length];//积,补码
char *finalproduct = new char[finalproduct_length];//积,真值
X1_length = store1_length + 1;
X2_length = store2_length - 1;
char *X1 = new char[X1_length];
char *X2 = new char[X2_length];//运算时需要的数形式
//int l1 = X1_length, l2 = X2_length;
Comp(muled, store1, store1_length);
if (store1[0] == '0') X1[0] = '0';//转换成运算所需的形式
else X1[0] = '1';
for (int i = 1, j = 0; j <= store1_length - 1; i++, j++)
X1[i] = store1[j];
Comp(muler, store2, store2_length);
if (store2[0] == '0') X2[0] = '0';//转换成运算所需的形式
else X2[0] = '1';
for (int i = 1, j = 2; j <= store2_length - 1; i++, j++)
X2[i] = store2[j];
store2_length = j;
char *store1 = new char[store1_length];//转换时暂存补码
char *store2 = new char[store2_length];
minus_length = store1_length + 1;
char *minus = new char[minus_length];//[-x]的补数
product_length = store1_length + store2_length - 3;
finalproduct_length = product_length + 1;
char *product = new char[product_length];//积,补码
char *finalproduct = new char[finalproduct_length];//积,真值
X1_length = store1_length + 1;
X2_length = store2_length - 1;
char *X1 = new char[X1_length];
char *X2 = new char[X2_length];//运算时需要的数形式
//int l1 = X1_length, l2 = X2_length;
Comp(muled, store1, store1_length);
if (store1[0] == '0') X1[0] = '0';//转换成运算所需的形式
else X1[0] = '1';
for (int i = 1, j = 0; j <= store1_length - 1; i++, j++)
X1[i] = store1[j];
Comp(muler, store2, store2_length);
if (store2[0] == '0') X2[0] = '0';//转换成运算所需的形式
else X2[0] = '1';
for (int i = 1, j = 2; j <= store2_length - 1; i++, j++)
X2[i] = store2[j];
剩余9页未读,继续阅读
资源评论
生查子月
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功