fehQlibs 26
Qlibs
Loading...
Searching...
No Matches
uint128p.c
Go to the documentation of this file.
1#include "uint_t.h"
2
10void uint128_pack(char s[16],uint128 u)
11{
12 s[0] = u.lo & 255; u.lo >>= 8;
13 s[1] = u.lo & 255; u.lo >>= 8;
14 s[2] = u.lo & 255; u.lo >>= 8;
15 s[3] = u.lo & 255; u.lo >>= 8;
16 s[4] = u.lo & 255; u.lo >>= 8;
17 s[5] = u.lo & 255; u.lo >>= 8;
18 s[6] = u.lo & 255; u.lo >>= 8;
19 s[7] = u.lo & 255; u.lo >>= 8;
20
21 s[8] = u.hi & 255; u.hi >>= 8;
22 s[9] = u.hi & 255; u.hi >>= 8;
23 s[10] = u.hi & 255; u.hi >>= 8;
24 s[11] = u.hi & 255; u.hi >>= 8;
25 s[12] = u.hi & 255; u.hi >>= 8;
26 s[13] = u.hi & 255; u.hi >>= 8;
27 s[14] = u.hi & 255; u.hi >>= 8;
28 s[15] = u.hi & 255;
29}
30void uint128_pack_big(char s[16],uint128 u)
31{
32 s[15] = u.lo & 255; u.lo >>= 8;
33 s[14] = u.lo & 255; u.lo >>= 8;
34 s[13] = u.lo & 255; u.lo >>= 8;
35 s[12] = u.lo & 255; u.lo >>= 8;
36 s[11] = u.lo & 255; u.lo >>= 8;
37 s[10] = u.lo & 255; u.lo >>= 8;
38 s[9] = u.lo & 255; u.lo >>= 8;
39 s[8] = u.lo & 255; u.lo >>= 8;
40
41 s[7] = u.hi & 255; u.hi >>= 8;
42 s[6] = u.hi & 255; u.hi >>= 8;
43 s[5] = u.hi & 255; u.hi >>= 8;
44 s[4] = u.hi & 255; u.hi >>= 8;
45 s[3] = u.hi & 255; u.hi >>= 8;
46 s[2] = u.hi & 255; u.hi >>= 8;
47 s[1] = u.hi & 255; u.hi >>= 8;
48 s[0] = u.hi & 255;
49}
50
51void uint128_unpack(char s[16],uint128 *u)
52{
53 uint128 result;
54 result.hi = result.lo = 0ULL;
55
56 result.hi = (unsigned char) s[15]; result.hi <<= 8;
57 result.hi += (unsigned char) s[14]; result.hi <<= 8;
58 result.hi += (unsigned char) s[13]; result.hi <<= 8;
59 result.hi += (unsigned char) s[12]; result.hi <<= 8;
60 result.hi += (unsigned char) s[11]; result.hi <<= 8;
61 result.hi += (unsigned char) s[10]; result.hi <<= 8;
62 result.hi += (unsigned char) s[9]; result.hi <<= 8;
63 result.hi += (unsigned char) s[8]; //correct
64
65 result.lo += (unsigned char) s[7]; result.lo <<= 8;
66 result.lo += (unsigned char) s[6]; result.lo <<= 8;
67 result.lo += (unsigned char) s[5]; result.lo <<= 8;
68 result.lo += (unsigned char) s[4]; result.lo <<= 8;
69 result.lo += (unsigned char) s[3]; result.lo <<= 8;
70 result.lo += (unsigned char) s[2]; result.lo <<= 8;
71 result.lo += (unsigned char) s[1]; result.lo <<= 8;
72 result.lo += (unsigned char) s[0];
73
74 *u = result;
75}
76void uint128_unpack_big(char s[16],uint128 *u)
77{
78 uint128 result;
79 result.hi = result.lo = 0ULL;
80
81 result.hi = (unsigned char) s[0]; result.hi <<= 8;
82 result.hi += (unsigned char) s[1]; result.hi <<= 8;
83 result.hi += (unsigned char) s[2]; result.hi <<= 8;
84 result.hi += (unsigned char) s[3]; result.hi <<= 8;
85 result.hi += (unsigned char) s[4]; result.hi <<= 8;
86 result.hi += (unsigned char) s[5]; result.hi <<= 8;
87 result.hi += (unsigned char) s[6]; result.hi <<= 8;
88 result.hi += (unsigned char) s[7];
89
90 result.lo += (unsigned char) s[8]; result.lo <<= 8;
91 result.lo += (unsigned char) s[9]; result.lo <<= 8;
92 result.lo += (unsigned char) s[10]; result.lo <<= 8;
93 result.lo += (unsigned char) s[11]; result.lo <<= 8;
94 result.lo += (unsigned char) s[12]; result.lo <<= 8;
95 result.lo += (unsigned char) s[13]; result.lo <<= 8;
96 result.lo += (unsigned char) s[14]; result.lo <<= 8;
97 result.lo += (unsigned char) s[15];
98
99 *u = result;
100}
void uint128_unpack(char s[16], uint128 *u)
Definition: uint128p.c:51
void uint128_pack_big(char s[16], uint128 u)
Definition: uint128p.c:30
void uint128_pack(char s[16], uint128 u)
Definition: uint128p.c:10
void uint128_unpack_big(char s[16], uint128 *u)
Definition: uint128p.c:76
additional types and pack routines
uint64_t hi
Definition: uint_t.h:70
uint64_t lo
Definition: uint_t.h:71