Logo

Programming-Idioms

History of Idiom 76 > diff from v57 to v58

Edit summary for version 58 by example12345:
[Cpp] sizeof

Version 57

2019-09-28, 16:42:43

Version 58

2019-09-28, 16:46:12

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>
#include <iostream>
Code
std::bitset<32> 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