From: Jack on
Hello,
I am wondering how to display a binary number with printf. (00000001b)

The specifier should look something like this
printf ("%b\n", a);

Have taken a look at my reference but did not find it
Thanks in advance
Jack


From: Igor Tandetnik on
Jack wrote:
> I am wondering how to display a binary number with printf. (00000001b)

printf won't help you with that. In fact, to the best of my knowledge, there is nothing in C or C++ standard library that could produce a binary representation of an integer. You'll have to roll your own.
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not necessarily a good idea. It is hard to be sure where they are going to land, and it could be dangerous sitting under them as they fly overhead. -- RFC 1925
From: Victor Bazarov on
Igor Tandetnik wrote:
> Jack wrote:
>> I am wondering how to display a binary number with printf.
>> (00000001b)
>
> printf won't help you with that. In fact, to the best of my
> knowledge, there is nothing in C or C++ standard library that could
> produce a binary representation of an integer. You'll have to roll
> your own.

Actually the std::bitset has the to_string function. It can help.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
From: Tom Walker on
"Victor Bazarov" <v.Abazarov(a)comAcast.net> wrote in message
news:hkudku$4vn$1(a)news.datemas.de...
> Igor Tandetnik wrote:
>> Jack wrote:
>>> I am wondering how to display a binary number with printf.
>>> (00000001b)
>>
>> printf won't help you with that. In fact, to the best of my
>> knowledge, there is nothing in C or C++ standard library that could
>> produce a binary representation of an integer. You'll have to roll
>> your own.
>
> Actually the std::bitset has the to_string function. It can help.
>

Also, the _itoa and _itow family of functions will produce a binary string
when 2 is used as the radix.

http://msdn.microsoft.com/en-us/library/yakksftt(VS.80).aspx
http://msdn.microsoft.com/en-us/library/0we9x30h(VS.80).aspx