43 return ( 1_u32 << n ) - 1;
44 }
else if ( 32 == n ) {
52 "00000000000000000000000000000001",
53 "00000000000000000000000000000010",
54 "00000000000000000000000000000100",
55 "00000000000000000000000000001000",
56 "00000000000000000000000000010000",
57 "00000000000000000000000000100000",
58 "00000000000000000000000001000000",
59 "00000000000000000000000010000000",
60 "00000000000000000000000100000000",
61 "00000000000000000000001000000000",
62 "00000000000000000000010000000000",
63 "00000000000000000000100000000000",
64 "00000000000000000001000000000000",
65 "00000000000000000010000000000000",
66 "00000000000000000100000000000000",
67 "00000000000000001000000000000000",
68 "00000000000000010000000000000000",
69 "00000000000000100000000000000000",
70 "00000000000001000000000000000000",
71 "00000000000010000000000000000000",
72 "00000000000100000000000000000000",
73 "00000000001000000000000000000000",
74 "00000000010000000000000000000000",
75 "00000000100000000000000000000000",
76 "00000001000000000000000000000000",
77 "00000010000000000000000000000000",
78 "00000100000000000000000000000000",
79 "00001000000000000000000000000000",
80 "00010000000000000000000000000000",
81 "00100000000000000000000000000000",
82 "01000000000000000000000000000000",
83 "10000000000000000000000000000000"
89 constexpr static uint8_t
testBytesMSB64_be[] = { 0xfa_u8, 0xde_u8, 0xaf_u8, 0xfe_u8, 0xde_u8, 0xaf_u8, 0xca_u8, 0xfe_u8 };
92 constexpr static std::string_view
testStringsMSB64_be[] = {
"11111010",
"11011110",
"10101111",
"11111110",
93 "11011110",
"10101111",
"11001010",
"11111110" };
94 constexpr static std::string_view
testStringMSB64_be =
"11111010" "11011110" "10101111" "11111110"
95 "11011110" "10101111" "11001010" "11111110";
100 constexpr static uint8_t
testBytesMSB64_le[] = { 0xfe_u8, 0xca_u8, 0xaf_u8, 0xde_u8, 0xfe_u8, 0xaf_u8, 0xde_u8, 0xfa_u8 };
103 constexpr static std::string_view
testStringsMSB64_le[] = {
"11111110",
"11001010",
"10101111",
"11011110",
104 "11111110",
"10101111",
"11011110",
"11111010" };
107 "11111110" "10101111" "11011110" "11111010";
111 constexpr static uint8_t
testBytesLSB64_be[] = { 0x5F_u8, 0x7B_u8, 0xF5_u8, 0x7F_u8, 0x7B_u8, 0xF5_u8, 0x53_u8, 0x7F_u8 };
114 constexpr static std::string_view
testStringsLSB64_be[] = {
"01011111",
"01111011",
"11110101",
"01111111",
115 "01111011",
"11110101",
"01010011",
"01111111" };
117 "01111011" "11110101" "01010011" "01111111";
121 constexpr static uint8_t
testBytesLSB64_le[] = { 0x7F_u8, 0x53_u8, 0xF5_u8, 0x7B_u8, 0x7F_u8, 0xF5_u8, 0x7B_u8, 0x5F_u8 };
125 "01111111" "11110101" "01111011" "01011111" };
126 constexpr static std::string_view
testStringLSB64_le =
"01111111" "01010011" "11110101" "01111011" "01111111" "11110101" "01111011" "01011111";
128 static void dumpData(
const std::string&
prefix,
const uint8_t* data,
size_t len) {
129 for(
size_t i = 0; i < len; ) {
130 fprintf(stderr,
"%s: %03zu: ",
prefix.c_str(), i);
131 for(
size_t j = 0; j < 8 && i < len; ++j, ++i ) {
132 const uint8_t v = 0xFF & data[i];
135 fprintf(stderr,
"\n");
139 fprintf(stderr,
"%s: Dump %s\n",
prefix.c_str(), data.
toString().c_str());
142 for(
size_t i = 0; i < len && !err; ) {
143 fprintf(stderr,
"%s: %03zu: ",
prefix.c_str(), i);
144 for(
size_t j = 0; j < 8 && i < len && !err; ++j, ++i ) {
149 fprintf(stderr,
"\n");
151 if( p != data.
seek(p) ) {
159 for(
size_t i = 0; i < pattern.length(); ++i ) {
160 if(
'1' == pattern[i] ) {
166 static uint64_t
toLong(
const std::string_view bitPattern) {
171 return (uint64_t)result;
173 static uint64_t
toInteger(
const std::string_view bitPattern) {
187 static constexpr const char*
strZeroPadding =
"0000000000000000000000000000000000000000000000000000000000000000";
189 if( 0 == bitCount ) {
static constexpr uint8_t testBytesLSB64_be[]
static constexpr std::string_view testStringsLSB64_be[]
static void dumpData(const std::string &prefix, jau::io::ByteStream &data)
static constexpr std::string_view testStringMSB64_le
static uint64_t toInteger(const std::string_view bitPattern)
static std::string toHexBinaryString(const uint64_t v, const int bitCount)
static uint64_t toLong(const std::string_view bitPattern)
static constexpr uint64_t testIntLSB64_le
static std::string toBinaryString(const uint64_t v, const size_t bitCount)
static constexpr uint8_t testBytesLSB64_le[]
static size_t getOneBitCount(std::string_view pattern)
static uint32_t getBitMask(size_t n)
Returns the 32 bit mask of n-bits, i.e.
static constexpr uint64_t testIntMSB64_le
static void dumpData(const std::string &prefix, jau::io::ByteStream &data, size_t len)
static constexpr std::string_view testStringsMSB64_le[]
static const std::vector< std::string_view > pyramid32bit_one
static constexpr const char * strZeroPadding
static void dumpData(const std::string &prefix, const uint8_t *data, size_t len)
static constexpr uint64_t testIntLSB64_be
static constexpr std::string_view testStringsLSB64_le[]
static constexpr std::string_view testStringsMSB64_be[]
static constexpr uint32_t UNSIGNED_INT_MAX_VALUE
static constexpr std::string_view testStringLSB64_be
static std::string toHexString(const int v)
static constexpr std::string_view testStringLSB64_le
static constexpr uint64_t testIntMSB64_be
static constexpr std::string_view testStringMSB64_be
static constexpr uint8_t testBytesMSB64_le[]
static constexpr uint8_t testBytesMSB64_be[]
static std::string toHexString(const int64_t v)
virtual size_t read(void *out, size_t length) noexcept=0
Read from the source.
virtual std::string toString() const noexcept=0
virtual size_type position() const noexcept=0
Returns the position indicator, similar to e.g.
virtual size_type remaining() const noexcept
Returns the remaining bytes, i.e.
virtual size_type seek(size_type newPos) noexcept=0
Sets position indicator for output-streams or input-streams with known length, similar to e....
std::string toBitString(const void *data, const nsize_t length, const bit_order_t bitOrder=bit_order_t::msb, const PrefixOpt prefix=PrefixOpt::prefix, size_t bit_len=0) noexcept
Produce a binary string representation of the given lsb-first byte values.
SizeBoolPair fromBitString(std::vector< uint8_t > &out, const uint8_t bitstr[], const size_t bitstr_len, const bit_order_t bitOrder=bit_order_t::msb, const Bool checkPrefix=Bool::True) noexcept
Converts a given binary string representation into a byte vector, lsb-first.
std::string toHexString(const void *data, const nsize_t length, const lb_endian_t byteOrder=lb_endian_t::big, const LoUpCase capitalization=LoUpCase::lower, const PrefixOpt prefix=PrefixOpt::prefix) noexcept
Produce a hexadecimal string representation of the given lsb-first byte values.
@ msb
Identifier for most-significant-bit (msb) first.