0
Is there any simple way to convert decimal system to binary system like i did with oct and hex?
#include <iostream> using namespace std; int main () { unsigned short A; cout << "A = "; cin >> A; cout << oct << A<<endl; cout<< hex<<A<<endl; return 0; }
2 Antworten
0
Probably setbase
https://en.cppreference.com/w/cpp/io/manip/setbase
0
Unfortunately setbase is working just with bases 8, 10 and 16 or default (the base in iostream is not treated as a number, but as a set of flags). Your options (as far as i know) are:
a) writing your own output wrapper
b) output a bitset<WIDTH>(n) https://en.cppreference.com/w/cpp/utility/bitset/operator_ltltgtgt2
c) using itoa from stdlib.h, which, while available in most compilers, is nonstandard http://www.cplusplus.com/reference/cstdlib/itoa/