55 void utob(
void *dest,
size_t dest_len, uint64_t src)
59 for (i = 0; (i < dest_len) && (i <
sizeof(uint64_t)); ++i)
61 ((uint8_t *) dest)[i] = (src >> (i * 8)) & 0xff;
64 for (; i < dest_len; ++i)
66 ((uint8_t *) dest)[i] = 0;
70 void itob(
void *dest,
size_t dest_len, int64_t src)
74 for (i = 0; (i < dest_len) && (i <
sizeof(int64_t)); ++i)
76 ((uint8_t *) dest)[i] = (src >> (i * 8)) & 0xff;
79 for (; i < dest_len; ++i)
81 if (((uint8_t *) dest)[dest_len - 1] & 0x80)
83 ((uint8_t *) dest)[i] = 0xff;
87 ((uint8_t *) dest)[i] = 0;
92 void ftob(
void *dest,
size_t dest_len,
double src,
double scale)
94 int64_t int_src = (src * scale);
95 itob(dest, dest_len, int_src);
100 void utob(
void *dest,
size_t dest_len, uint32_t src)
102 utob(dest, dest_len, (uint64_t) src);
105 void utob(
void *dest,
size_t dest_len, uint16_t src)
107 utob(dest, dest_len, (uint64_t) src);
110 void itob(
void *dest,
size_t dest_len, int32_t src)
112 itob(dest, dest_len, (int64_t) src);
115 void itob(
void *dest,
size_t dest_len, int16_t src)
117 itob(dest, dest_len, (int64_t) src);
120 uint64_t
btou(
void *src,
size_t src_len)
124 if (!src_len) {
return 0; }
125 size_t i = src_len - 1;
128 retval = retval << 8;
129 retval |= ((uint8_t *) src)[i];
135 int64_t
btoi(
void *src,
size_t src_len)
138 size_t i =
sizeof(int64_t);
140 if (!src_len) {
return 0; }
143 for (; i >= src_len; --i)
145 retval = retval << 8;
146 if (((uint8_t *) src)[src_len - 1] & 0x80)
153 retval = retval << 8;
154 retval |= ((uint8_t *) src)[i];
160 double btof(
void *src,
size_t src_len,
double scale)
162 double retval =
btoi(src, src_len);
163 return retval /= scale;
uint64_t btou(void *src, size_t src_len)
void utob(void *dest, size_t dest_len, uint64_t src)
void itob(void *dest, size_t dest_len, int64_t src)
int64_t btoi(void *src, size_t src_len)
void ftob(void *dest, size_t dest_len, double src, double scale)
double btof(void *src, size_t src_len, double scale)