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';
More Related Contents:
- How do you convert decimal in integer to hexadecimal in integer? [closed]
- How do I print a double value with full precision using cout?
- Output unicode strings in Windows console app
- Why does reading a record struct fields from std::istream fail, and how can I fix it?
- C++ Standard Library: How to write wrappers for cout, cerr, cin and endl?
- Does the C++ standard mandate poor performance for iostreams, or am I just dealing with a poor implementation?
- ‘printf’ vs. ‘cout’ in C++
- How to output a character as an integer through cout?
- Difference between iostream and iostream.h
- How to read a file line by line or a whole text file at once?
- How do I deal with the max macro in windows.h colliding with max in std?
- Prevent scientific notation in ostream when using
- Read binary data from std::cin
- Why unsigned int 0xFFFFFFFF is equal to int -1?
- Alternative function in iostream.h for getch() of conio.h?
- C++ – Decimal to binary converting
- Are there any tricks to use std::cin to initialize a const variable?
- How do the stream manipulators work?
- What the point of using std::ios_base::binary?
- What exactly is streambuf? How do I use it?
- Reading and writing to the same file using the same fstream
- Efficient bitwise operations for counting bits or find the right|left most ones
- Do I have to use #include beside ?
- What is the difference between cout, cerr, clog of iostream header in c++? When to use which one?
- What’s the difference between while(cin) and while(cin >> num)
- Loading a file into a vector
- Fastest way to Convert String to Binary?
- Reading files larger than 4GB using c++ stl
- What is the binary representation of a boolean value in c#
- Are there binary memory streams in C++