Logo

Programming-Idioms

History of Idiom 76 > diff from v59 to v60

Edit summary for version 60 by example12345:
[Cpp] oops

Version 59

2019-09-28, 16:48:37

Version 60

2019-09-28, 16:49:33

Idiom #76 Binary digits from an integer

Create the string s of integer x written in base 2.

E.g. 13 -> "1101"

Idiom #76 Binary digits from an integer

Create the string s of integer x written in base 2.

E.g. 13 -> "1101"

Extra Keywords
int radix
Extra Keywords
int radix
Imports
#include <bitset>
#include <iostream>
Imports
#include <bitset>
Code
std::bitset<sizeof(x)*8> y(x);
auto s = y.to_string();
Code
std::bitset<sizeof(x)*8> y(x);
auto s = y.to_string();
Doc URL
https://en.cppreference.com/w/cpp/utility/bitset
Doc URL
https://en.cppreference.com/w/cpp/utility/bitset
Origin
https://stackoverflow.com/questions/2890502/how-to-convert-an-int-to-a-binary-string-representation-in-c#2891296
Origin
https://stackoverflow.com/questions/2890502/how-to-convert-an-int-to-a-binary-string-representation-in-c#2891296