hello,

I am using a bitset constructor to pass an unsigned long and create a bitset object.

bitset<32> bvec(012);
string mystring=bvec.to_string<char,char_traits<char>,allocator<char> 
>();

 cout << "mystring: " << mystring << endl;

here the least significant 4 bits are- 1010

when i write

bitset<32> bvec(12);

the least significant bits are 1100.

the second case I understand, 1100 is the binary for 12.
How come 012 gives me 1010??

thanks,
bhaskar

Recommended Answers

All 4 Replies

>How come 012 gives me 1010??
012 is 10 in octal, which has a bit pattern of 1010.

does the '0' in '012' signify that it is octal?

>does the '0' in '012' signify that it is octal?
Yes, much like how 0x (or 0X) makes it hexadecimal. You can read more about it here.

thanks a lot

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.