summaryrefslogtreecommitdiff
path: root/sys/src/libmp/port/letomp.c
diff options
context:
space:
mode:
authorTaru Karttunen <taruti@taruti.net>2011-03-30 15:46:40 +0300
committerTaru Karttunen <taruti@taruti.net>2011-03-30 15:46:40 +0300
commite5888a1ffdae813d7575f5fb02275c6bb07e5199 (patch)
treed8d51eac403f07814b9e936eed0c9a79195e2450 /sys/src/libmp/port/letomp.c
Import sources from 2011-03-30 iso image
Diffstat (limited to 'sys/src/libmp/port/letomp.c')
-rwxr-xr-xsys/src/libmp/port/letomp.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/sys/src/libmp/port/letomp.c b/sys/src/libmp/port/letomp.c
new file mode 100755
index 000000000..e23fed21e
--- /dev/null
+++ b/sys/src/libmp/port/letomp.c
@@ -0,0 +1,28 @@
+#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);
+ 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;
+}