C语言-大数减法

typedef unsigned int        u32;
typedef unsigned char       u8;
typedef unsigned short      u16;
typedef unsigned long long  u64;

 


/******************************************************************************

unsigned integer sub
if underflow, return 1
res = a - b
******************************************************************************/
u32 BigSub(u32 *Res,u32 *Minuend,u32 *Subtrahend,u32 ulLen)
{
    u32 carry=0;
u64 _W;
while (ulLen--)
{
_W = ((u64)*Minuend++) - ((u64)*Subtrahend++) - (u64)carry;
*Res++ = (u32)_W;
carry = (u32)(_W >> 32);
carry = ~carry + 1;
}
return carry;

}

// 数据翻转
void top_swap_bottom(u32 *res,u32 resLen)
{
int i;
for (i=0;i<resLen/2;i++)
{
res[i] = res[i] ^res[resLen-i-1];
res[resLen-i-1]= res[i] ^res[resLen-i-1];
res[i] = res[i] ^res[resLen-i-1];
}
}

// 举个例子


int main()

{

u32 res[8]={0x00};

u32 a[8]={0x00223344,0x99887766,0x00223344,0x99887766,0x00223344,0x99887766,0x00223344,0x99887766};

u32 b[8]={0x00223344,0x22113234,0x00223344,0x99887766,0x00223344,0x99887766,0x99776655,0x99776655};

top_swap_bottom(a,8);

top_swap_bottom(b,8);

BigSub(res,a,b,8,8);

top_swap_bottom(res,8);

return 0;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

乌苏舞

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值