资源简介
用字符串十进制方式和整形数组2的32方进制。前者采用c++重载技术能更方便的进一步利用
代码片段和文件信息
#include
#include
#define N 20
#define ISPOWEROFTWO(x) 0==((x)&((x)-1))
int factorial(int n)
{
int product=1;
while(n>0)
product*=n--;
return product;
}
int rank(unsigned k)
{
int ifirstBitnum=0;
for(i=1;i<=32;i++)
{
if(k&(unsigned)1==1)
{
firstBit=i;
num++;
}
k>>=1;
}
if(num==0||firstBit<1)
return 1;
return factorial(firstBit-1)/(factorial(num)*factorial(firstBit-1-num))+1;
}
int divide(int aint bint &r)
{
int iq=0;
while(a-b>=0)
{
for(i=0;a-b>=0;b<<=1i++);
b>>=1;i--;
q+=(1< a-=b;b>>=i;
}
r=a;
return q;
}
unsigned *addition(const unsigned a[]const unsigned b[])
{
unsigned *res=(unsigned*)malloc(sizeof(unsigned)*N);
unsigned k=0;
for(int i=N-1;i>=0;i--)
{
res[i]=a[i]+b[i]+k;
k=res[i] }
return res;
}
unsigned *addition(const unsigned a[]int nconst unsigned b[]int m)
{
int max=n>m?n:m;
unsigned *t1=(unsigned *)malloc(sizeof(unsigned)*max);
unsigned *t2=(unsigned *)malloc(sizeof(unsigned)*max);
for(int i=n-1j=max-1;i>=0;i--)
t1[j--]=a[i];
for(;j>=0;j--)
t1[j]=0;
for(i=m-1j=max-1;i>=0;i--)
t2[j--]=b[i];
for(;j>=0;j--)
t2[j]=0;
unsigned *res=(unsigned*)malloc(sizeof(unsigned)*max);
unsigned k=0;
for(i=max-1;i>=0;i--)
{
res[i]=t1[i]+t2[i]+k;
k=res[i] }
free(t1);
free(t2);
return res;
}
void countUp(unsigned a[]const unsigned b[]int n)
{
unsigned k=0;
for(int i=n-1;i>=0;i--)
{
a[i]=a[i]+b[i]+k;
k=a[i] }
}
unsigned *substraction(const unsigned a[]const unsigned b[])
{
unsigned k=0*t=(unsigned *)malloc(sizeof(unsigned)*N);
for(int i=N-1;i>=0;i--)
{
t[i]=a[i]-b[i]-k;
k=t[i]>=a[i]&&(b[i]!=0||k!=0)?1:0;
}
return t;
}
void countDown(unsigned a[]const unsigned b[])
{
unsigned k=0;
unsigned t;
for(int i=N-1;i>=0;i--)
{
t=a[i];
a[i]=a[i]-b[i]-k;
k=a[i]>=t&&(b[i]!=0||k!=0)?1:0;
}
}
unsigned *circleLeft(unsigned *aint n)
{
int i;
for(i=1n%=32;i<=n;i++)
{
if(*a&0x80000000)
{
*a<<=1;
*a+=1;
}
else
*a<<=1;
}
return a;
}
unsigned *circleRight(unsigned *aint n)
{
int i;
for(i=1n%=32;i<=n;i++)
{
if(*a&0x1)
{
*a>>=1;
*a|=0x80000000;
}
else
*a>>=1;
}
return a;
}
void swapLowNbits(unsigned *aunsigned *bint n)
{
unsigned t=0;
for(int i=0;i {
t=*a&(1< *a=*a&~(1< *b=*b&~(1< }
}
void swaphighNbits(unsigned *aunsigned *bint n)
{
unsigned t=0;
for(int i=0;i {
t=*a&(0x80000000>>i);
*a=*a&~(0x80000000>>i)|*b&(0x80000000>>i);
*b=*b&~(0x80000000>>i)|t;
}
}
void moveLeft(unsigned a[]int mint n)
{
int i;
while(n-32>=0)
{
for(i=0;i a[i]=a[i+1];
a[i]=0;
n-=32;
}
if(n>0)
{
unsigned k=0;
for(i=m-1;i>=0;i--)
{
circl
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 5991 2011-11-28 15:33 2的32次方进制\GNumber.cpp
文件 1285 2011-10-09 11:57 十进制方式\BigNumber.h
文件 7617 2011-10-19 19:28 十进制方式\BigNumber.cpp
目录 0 2012-01-08 15:30 2的32次方进制
目录 0 2012-01-08 15:29 十进制方式
----------- --------- ---------- ----- ----
14893 5
- 上一篇:LPC线性预测分析及编码
- 下一篇:航空订票系统_数据结构课程设计
评论
共有 条评论