Bit operation

2014/08/29 15:56
Reading 369

In addition to static_stream and stream, which can read and write bit by bit, TBOX also provides a more primitive and low-level bit data operation interface. For example, the bit reading operation of a data pointer directly can use the tb_bits_get_xxx and tb_bits_set_xxx serial interfaces of the utils library, which is more lightweight:

 //P points to a data address tb_byte_t* p = data; //Read 16 bit data by big end tb_uint16_t u16_be = tb_bits_get_u16_be(p); //Read 24 bit data by small terminal tb_uint32_t u24_le = tb_bits_get_u24_le(p); //Read 32-bit data by local end tb_uint32_t u32_ne = tb_bits_get_u32_ne(p); //Read 64 bit data by big end tb_uint64_t u64_be = tb_bits_get_u64_be(p); //Read the next 5 unsigned data starting from bit 1 tb_uint32_t u5 = tb_bits_get_ubits32(p, 1, 5); //Read floating point value by big end tb_float_t float_be = tb_bits_get_float_be(p); //Read double precision floating-point values by floating point big end and word small end tb_double_t double_ble = tb_bits_get_double_ble(p); //Read double precision floating-point value by floating-point local end and word local end tb_double_t double_nne = tb_bits_get_double_nne(p); //Swap unsigned 16 bit values u16 = tb_bits_swap_u16(u16); //Swap unsigned 32-bit values u32 = tb_bits_swap_u32(u32); //Swap unsigned 64 bit values u64 = tb_bits_swap_u64(u64); //Convert the local u32 value to the big u32 value u32_be = tb_bits_ne_to_be_u32(u32_ne); //Convert the u64 value of the small end to the u64 value of the big end u64_be = tb_bits_ne_to_be_u32(u64_le); //Get the leading 0 digits of u32 in the big end order count = tb_bits_cl0_u32_be(val); //Get the bits of leading 1 of u64 in the order of small end count = tb_bits_cl1_u64_le(val); //Get the index position of the first bit 0 of u32 in the big end order index = tb_bits_fl0_u32_be(val); //Get the index position of the first bit 1 of u64 in the small end order index = tb_bits_fl1_u64_le(val); //Get the total number of bit 0 of u32 count = tb_bits_cb0_u32(val); //Get the total number of bits 1 of u63 count = tb_bits_cb1_u64(val);

Expand to read the full text
Loading
Click to lead the topic 📣 Post and join the discussion 🔥
Reward
zero comment
four Collection
zero fabulous
 Back to top
Top