This commit is contained in:
Russ Cox
2005-08-08 12:50:13 +00:00
parent 0189e66e88
commit 934846f35c
382 changed files with 62614 additions and 0 deletions

29
libmp/letomp.c Normal file
View File

@ -0,0 +1,29 @@
#include "os.h"
#include <mp.h>
#include "dat.h"
// convert a little endian byte array (least significant byte first) to an mpint
mpint*
letomp(uchar *s, uint n, mpint *b)
{
int i=0, m = 0;
mpdigit x=0;
if(b == nil)
b = mpnew(0);
mpbits(b, 8*n);
b->top = DIGITS(8*n);
for(; n > 0; n--){
x |= ((mpdigit)(*s++)) << i;
i += 8;
if(i == Dbits){
b->p[m++] = x;
i = 0;
x = 0;
}
}
if(i > 0)
b->p[m++] = x;
b->top = m;
return b;
}