How to select first 8 bit from bitset<16> in c++?

H.Ghassami

I have a variable and it's type is bitset<16>. I want to get first 8 bit of my variable and put it into char variable. I know how to convert bitset to char, but I don't know how to select first 8 bit and convert it to char.

Benjamin Debotté

If by "first 8 bits" you're talking about 8-MSB, consider using the >> operator :

#include <iostream>

int main() {
    std::bitset<16> myBits(0b0110110001111101);
    char reg = 0;

    reg = static_cast<char>(myBits.to_ulong() >> 8);
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to Add signed 8-bit from unsigned 16-bit?

From Dev

How to Add signed 8-bit from unsigned 16-bit?

From Dev

How does OpenCV imread convert between 16 bit and 8 bit

From Dev

How to convert 8bit sound to 16bit

From Dev

convert bitset<64> to string every 8 bit

From Dev

Swap the first 8 bits and the last 8 bits of 16-bit value

From Dev

Convert Pixel Buffer to B8G8R8A8_UNorm from 16Bit

From Dev

Char size 8 bit or 16 bit?

From Dev

Linear PCM 16 bit to 8 bit

From Dev

How to find the first bit that is different in C?

From Dev

Calculating 16-bit integer value from two 8-bit integers?

From Dev

Create one 16-bit vector from two 8-bit vectors

From Dev

MongoDB C++ Driver - 8-bit and 16-bit integers?

From Dev

convert from BitArray to 16-bit unsigned integer in c#

From Dev

Reading 16-bit integers from binary file c++

From Dev

convert from BitArray to 16-bit unsigned integer in c#

From Dev

Inserting an array of 16-bit ints to MySQL, from C

From Dev

How to advance in a queue with 8-bit members and combine couples into 16-bit values

From Dev

How do you convert a 16 bit unsigned integer to a larger 8 bit unsigned integer?

From Dev

If a CPU has a 16 bit address bus and 8 bit words, how much memory can it address?

From Dev

How can I convert an image with 16 bit depth to 8 bit depth

From Dev

How do I compute the 16-bit dot product of two arrays containing 8-bit values?

From Dev

How to convert 16 bit unsigned int to 8 bit unsigned char & finally return in an unsigned char*?

From Dev

How to downgrade 16 bit depth gray scale to 8 bit depth image (rgb 24)

From Dev

How to read signed 16bit integers from QFile?

From Dev

C - How to check if 8 bits are in 32 bit?

From Dev

OpenCV (C++): how to save a 16bit image?

From Dev

Z3Py: How should I represent some 32-bit; 16-bit and 8-bit registers?

From Dev

Is there a builtin bitset that's similar to the std::bitset from C++?

Related Related

  1. 1

    How to Add signed 8-bit from unsigned 16-bit?

  2. 2

    How to Add signed 8-bit from unsigned 16-bit?

  3. 3

    How does OpenCV imread convert between 16 bit and 8 bit

  4. 4

    How to convert 8bit sound to 16bit

  5. 5

    convert bitset<64> to string every 8 bit

  6. 6

    Swap the first 8 bits and the last 8 bits of 16-bit value

  7. 7

    Convert Pixel Buffer to B8G8R8A8_UNorm from 16Bit

  8. 8

    Char size 8 bit or 16 bit?

  9. 9

    Linear PCM 16 bit to 8 bit

  10. 10

    How to find the first bit that is different in C?

  11. 11

    Calculating 16-bit integer value from two 8-bit integers?

  12. 12

    Create one 16-bit vector from two 8-bit vectors

  13. 13

    MongoDB C++ Driver - 8-bit and 16-bit integers?

  14. 14

    convert from BitArray to 16-bit unsigned integer in c#

  15. 15

    Reading 16-bit integers from binary file c++

  16. 16

    convert from BitArray to 16-bit unsigned integer in c#

  17. 17

    Inserting an array of 16-bit ints to MySQL, from C

  18. 18

    How to advance in a queue with 8-bit members and combine couples into 16-bit values

  19. 19

    How do you convert a 16 bit unsigned integer to a larger 8 bit unsigned integer?

  20. 20

    If a CPU has a 16 bit address bus and 8 bit words, how much memory can it address?

  21. 21

    How can I convert an image with 16 bit depth to 8 bit depth

  22. 22

    How do I compute the 16-bit dot product of two arrays containing 8-bit values?

  23. 23

    How to convert 16 bit unsigned int to 8 bit unsigned char & finally return in an unsigned char*?

  24. 24

    How to downgrade 16 bit depth gray scale to 8 bit depth image (rgb 24)

  25. 25

    How to read signed 16bit integers from QFile?

  26. 26

    C - How to check if 8 bits are in 32 bit?

  27. 27

    OpenCV (C++): how to save a 16bit image?

  28. 28

    Z3Py: How should I represent some 32-bit; 16-bit and 8-bit registers?

  29. 29

    Is there a builtin bitset that's similar to the std::bitset from C++?

HotTag

Archive