##// END OF EJS Templates
bitmanipulation: add missing include of string.h...
Martin von Zweigbergk -
r32646:b4356d1c default
parent child Browse files
Show More
@@ -1,53 +1,55
1 1 #ifndef _HG_BITMANIPULATION_H_
2 2 #define _HG_BITMANIPULATION_H_
3 3
4 #include <string.h>
5
4 6 #include "compat.h"
5 7
6 8 static inline uint32_t getbe32(const char *c)
7 9 {
8 10 const unsigned char *d = (const unsigned char *)c;
9 11
10 12 return ((d[0] << 24) |
11 13 (d[1] << 16) |
12 14 (d[2] << 8) |
13 15 (d[3]));
14 16 }
15 17
16 18 static inline int16_t getbeint16(const char *c)
17 19 {
18 20 const unsigned char *d = (const unsigned char *)c;
19 21
20 22 return ((d[0] << 8) |
21 23 (d[1]));
22 24 }
23 25
24 26 static inline uint16_t getbeuint16(const char *c)
25 27 {
26 28 const unsigned char *d = (const unsigned char *)c;
27 29
28 30 return ((d[0] << 8) |
29 31 (d[1]));
30 32 }
31 33
32 34 static inline void putbe32(uint32_t x, char *c)
33 35 {
34 36 c[0] = (x >> 24) & 0xff;
35 37 c[1] = (x >> 16) & 0xff;
36 38 c[2] = (x >> 8) & 0xff;
37 39 c[3] = (x) & 0xff;
38 40 }
39 41
40 42 static inline double getbefloat64(const char *c)
41 43 {
42 44 const unsigned char *d = (const unsigned char *)c;
43 45 double ret;
44 46 int i;
45 47 uint64_t t = 0;
46 48 for (i = 0; i < 8; i++) {
47 49 t = (t<<8) + d[i];
48 50 }
49 51 memcpy(&ret, &t, sizeof(t));
50 52 return ret;
51 53 }
52 54
53 55 #endif
General Comments 0
You need to be logged in to leave comments. Login now