MCPcopy Create free account
hub / github.com/ElementsProject/elements / getByte

Function getByte

src/simplicity/bitstring.h:42–53  ·  view source on GitHub ↗

Return 8 bits from a bitstring staring from the nth bit. * * Precondition: NULL != s * n + 8 <= s->len; */

Source from the content-addressed store, hash-verified

40 * n + 8 <= s->len;
41 */
42static inline uint_fast8_t getByte(const bitstring *s, size_t n) {
43 simplicity_assert(8 <= s->len);
44 simplicity_assert(n <= s->len - 8);
45 size_t total_offset = s->offset + n;
46 if (total_offset % CHAR_BIT <= CHAR_BIT - 8) {
47 return (uint_fast8_t)(0xff & (s->arr[total_offset / CHAR_BIT] >> (CHAR_BIT - 8 - (total_offset % CHAR_BIT))));
48 } else {
49 /* CHAR_BIT < total_offset % CHAR_BIT + 8 */
50 return (uint_fast8_t)(0xff & (((1U * s->arr[total_offset / CHAR_BIT]) << (total_offset % CHAR_BIT - (CHAR_BIT - 8)))
51 | (s->arr[total_offset / CHAR_BIT + 1] >> (CHAR_BIT - (total_offset % CHAR_BIT - (CHAR_BIT - 8))))));
52 }
53}
54#endif

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected