The easiest way is probably to create an std::bitset
representing the value, then stream that to cout
.
#include <bitset> ... char a = -58; std::bitset<8> x(a); std::cout << x << '\n'; short c = -315; std::bitset<16> y(c); std::cout << y << '\n';
Related Posts:
- outputting ascii table in C++
- How to read a file line by line or a whole text file at once?
- Why unsigned int 0xFFFFFFFF is equal to int -1?
- C++ – Decimal to binary converting
- ‘cout’ was not declared in this scope
- How to reverse an std::string? [duplicate]
- streambuf::xsgetn and state flags
- ‘cout’ was not declared in this scope
- Why would we call cin.clear() and cin.ignore() after reading input?
- Reading from text file until EOF repeats last line
- Fastest way to Convert String to Binary?
- cin.eof() functionality
- Reading and writing binary file
- The difference between cin.ignore and cin.sync
- Xcode 11.1: iostream’ file not found
- What’s the difference between while(cin) and while(cin >> num)
- operator << must take exactly one argument
- How to solve “Unresolved inclusion:
” in a C++ file in Eclipse CDT? - How to create a dynamic array of integers
- How to implement 2D vector array?
- What is the difference between g++ and gcc?
- What is the best way to use a HashMap in C++?
- What is the difference between float and double?
- How do I find the length of an array?
- What’s the C++ version of Java’s ArrayList
- What is the difference between “long”, “long long”, “long int”, and “long long int” in C++?
- What are the rules of the std::cin object in C++?
- ‘g++’ is not recognized as an internal or external command, operable program or batch file
- How do I convert a double into a string in C++?
- How to create timer events using C++ 11?
- How to concatenate two strings in C++?
- ‘g++’ is not recognized as an internal or external command, operable program or batch file
- Read file line by line using ifstream in C++
- Virtual/pure virtual explained
- error: redefinition of class
- Officially, what is typename for?
- How do I iterate over the words of a string?
- error: lvalue required as unary & operand
- C/C++ JSON parser
- C++ Parsing input string to variables
- Segmentation fault error 11 C++
- Why doesn’t C++ have a garbage collector?
- How does ifstream’s eof() work?
- terminate called after throwing an instance of ‘std::invalid_argument’ what(): stoi
- How to find memory leak in a C++ code/project?
- invalid use of non-static member function
- libstdc++-6.dll not found
- vector
::size_type in C++ - What does ‘\0’ mean?
- cin >> “no operator matches these operands”
- C++ on mac : linker command failed with exit code 1 (use -v to see invocation)
- Correct way to use cin.fail()
- Destructor for a linked List
- Why use a new call with a C++ ‘vector’?
- Identifier is undefined
- What are the most widely used C++ vector/matrix math/linear algebra libraries, and their cost and benefit tradeoffs?
- Arduino sprintf float not formatting
- How to end C++ code
- Delete 2D array C++
- class not declared in scope – even though .h was included
- Best C/C++ Network Library
- How to check that an element is in a std::set?
- Best way to extract a subvector from a vector?
- How do malloc() and free() work?
- Call to implicitly deleted copy constructor in LLVM
- C++ string to enum
- c++ “Incomplete type not allowed” error accessing class reference information (Circular dependency with forward declaration)
- why is string not declared in scope
- How does rhs work?
- error: expected unqualified-id before ‘.’ token //(struct)
- Base class undefined
- C++ – Assigning null to a std::string
- The program can’t start because libgcc_s_dw2-1.dll is missing
- C++ – Too Many Initializers for Arrays
- Reading string by char till end of line C/C++
- G++ undefined reference to class::function
- Is string::compare reliable to determine alphabetical order?
- How to return a struct from a function in C++?
- C++ printing boolean, what is displayed?
- Error : aggregate ‘first one’ has incomplete type and cannot be defined
- CMake : C and CXX compiler identification is unknown Win10 CMakeGUI
- Error “Unterminated conditional directive” in cross-referencing headers
- C++ template – error: expected initializer before ‘<' token
- non-member function cannot have cv-qualifier
- too many initializers for ‘int [0]’ c++
- function does not take 1 arguments c++
- overloaded function with no contextual type information
- How exactly do lookup tables work and how to implement them?
- Vector declaration “expected parameter declarator”
- C++ Destructors with Vectors, Pointers,
- error C2065: ‘cout’ : undeclared identifier
- How to get the MD5 hash of a file in C++?
- Why do I get: -9223372036854775808
- Return a 2d array from a function
- Linker error: “linker input file unused because linking not done”, undefined reference to a function in that file
- What is the difference among ios::app, out, and trunc in c++?
- Where can I find ‘winmm.lib’ (I’m using Visual Studio 2012)
- What is a `char*`?
- Does static constexpr variable inside a function make sense?
- “Incomplete type not allowed ” when creating std::ofstream objects