lundi 3 octobre 2022

Why uint8_t is not printing any value [duplicate]

I was running the below code on online compiler Link understand its output.

#include <iostream>
using namespace std;

static const uint32_t SHIFT_TO_GET_BUFFER_TYPE  = 0x8;

int main() {
uint32_t dword  = 0x09020002;

uint8_t bufferType1     = dword >> SHIFT_TO_GET_BUFFER_TYPE;
uint32_t bufferType2    = dword >> SHIFT_TO_GET_BUFFER_TYPE;

cout << "buffer type 1 = "  << std::hex << bufferType1 << "\n";
cout << "buffer type 2 = "  << std::hex << bufferType2 << "\n";

/*
Output : 
    buffer type 1 = 
    buffer type 2 = 90200
*/

return 0;
}

But I got no output for uint8_t bufferType1 while running the same code in Visual studio 2017 found the value of bufferType1 to be 0.

Can you suggest why uint8_t bufferType1 got no value and what is the correct data type I should use to get the value in either 0 or 1 ?

Expected Input/Output : 
dword = 0x09020002  // Output 0
dword = 0x09050002  // Output 1

Aucun commentaire:

Enregistrer un commentaire