Is directly putting in binary possible C++

Is putting in binary as a value possible? I want something like char test = 00101011 and it will become 43. I know this is possible by making a function that converts binary to decimal (which can be inputted) but thats not direct and Im pretty sure it takes time.

>Solution :

You need to put the prefix 0b.

#include <iostream>

int main()
    char c = 0b00101011;
    std::cout << static_cast<int>(c) << std::endl;

Leave a Reply