tletomp.c - plan9port - [fork] Plan 9 from user space
HTML git clone git://src.adamsgaard.dk/plan9port
DIR Log
DIR Files
DIR Refs
DIR README
DIR LICENSE
---
tletomp.c (435B)
---
1 #include "os.h"
2 #include <mp.h>
3 #include "dat.h"
4
5 /* convert a little endian byte array (least significant byte first) to an mpint */
6 mpint*
7 letomp(uchar *s, uint n, mpint *b)
8 {
9 int i=0, m = 0;
10 mpdigit x=0;
11
12 if(b == nil)
13 b = mpnew(0);
14 mpbits(b, 8*n);
15 for(; n > 0; n--){
16 x |= ((mpdigit)(*s++)) << i;
17 i += 8;
18 if(i == Dbits){
19 b->p[m++] = x;
20 i = 0;
21 x = 0;
22 }
23 }
24 if(i > 0)
25 b->p[m++] = x;
26 b->top = m;
27 return b;
28 }