56 void utob(
void *dest,
size_t dest_len, uint64_t src)
60 for (i = 0; (i < dest_len) && (i <
sizeof(uint64_t)); ++i)
62 ((uint8_t *) dest)[i] = (src >> (i * 8)) & 0xff;
65 for (; i < dest_len; ++i)
67 ((uint8_t *) dest)[i] = 0;
71 void itob(
void *dest,
size_t dest_len, int64_t src)
75 for (i = 0; (i < dest_len) && (i <
sizeof(int64_t)); ++i)
77 ((uint8_t *) dest)[i] = (src >> (i * 8)) & 0xff;
80 for (; i < dest_len; ++i)
82 if (((uint8_t *) dest)[dest_len - 1] & 0x80)
84 ((uint8_t *) dest)[i] = 0xff;
88 ((uint8_t *) dest)[i] = 0;
93 void ftob(
void *dest,
size_t dest_len,
double src,
double scale)
95 int64_t int_src = (src * scale);
96 itob(dest, dest_len, int_src);
101 void utob(
void *dest,
size_t dest_len, uint32_t src)
103 utob(dest, dest_len, (uint64_t) src);
106 void utob(
void *dest,
size_t dest_len, uint16_t src)
108 utob(dest, dest_len, (uint64_t) src);
111 void itob(
void *dest,
size_t dest_len, int32_t src)
113 itob(dest, dest_len, (int64_t) src);
116 void itob(
void *dest,
size_t dest_len, int16_t src)
118 itob(dest, dest_len, (int64_t) src);
121 uint64_t
btou(
void *src,
size_t src_len)
125 if (!src_len) {
return 0; }
126 size_t i = src_len - 1;
129 retval = retval << 8;
130 retval |= ((uint8_t *) src)[i];
136 int64_t
btoi(
void *src,
size_t src_len)
139 size_t i =
sizeof(int64_t);
141 if (!src_len) {
return 0; }
144 for (; i >= src_len; --i)
146 retval = retval << 8;
147 if (((uint8_t *) src)[src_len - 1] & 0x80)
154 retval = retval << 8;
155 retval |= ((uint8_t *) src)[i];
161 double btof(
void *src,
size_t src_len,
double scale)
163 double retval =
btoi(src, src_len);
164 return retval /= scale;
void utob(void *dest, size_t dest_len, uint64_t src)
int64_t btoi(void *src, size_t src_len)
uint64_t btou(void *src, size_t src_len)
void ftob(void *dest, size_t dest_len, double src, double scale)
void itob(void *dest, size_t dest_len, int64_t src)
double btof(void *src, size_t src_len, double scale)