How to assign an 8-bit value directly to a char in C++

1 Answer

0 votes
#include <iostream>

int main() {
    unsigned char ch = 0b10101010; 
    
    std::cout << "Value: " << static_cast<int>(ch) << std::endl; 
}



/*
run:

Value: 170

*/

 



answered Jul 29, 2025 by avibootz
...