Output integral for ostringstream as binary?

I just realized that you can use a bit set to output binary data to a stream based on the (fixed) size of the bit set. What is the least-additional syntax way to output binary data to a stream using integrals?

To show what I mean, here is the program and its output. I would like the second line of the output of this program to be identical to the first line, but without resorting to the method used to output the third line.

int main()
{
  ostringstream bsout, uout, xout;
  bitset<32> bs (0x31323334);
  unsigned u = 0x31323334;

  bsout << bs;
  cout << bsout.str() << endl;

  uout << u;
  cout << uout.str() << endl;

  xout << bitset<32>(u);
  cout << xout.str() << endl;

  return 0;
}


00110001001100100011001100110100
825373492
00110001001100100011001100110100
+3
source share
1 answer

, std::bin, oct hex. bitset - .

+2

Source: https://habr.com/ru/post/1745142/


All Articles