Topic: ios_base format flags and basefield manipulators: dec, hex, oct, but no bin?


Author: godwater@gmail.com
Date: Wed, 28 Mar 2007 11:34:26 CST
Raw View
On 3      28      ,             2  18      , "Daniel Kr      gler" <daniel.krueg...@googlemail.com>
wrote:
> Steve Ward schrieb:
>
> > I'm curious why there is no "bin" format flag or basefield
> > manipulator.  There is dec (base 10), hex (base 16), and oct (base 8),
> > but no bin (understood to be base 2).
>
> > Is there a good reason why bin doesn't exist?  If not, then I'm
> > tempted to write a proposal.
>
> > I looked in the index and there is nothing named "bin" so a name
> > conflict can't be the reason.  Also, I don't have a copy of D&E handy,
> > in case the answer lies therein.
>
> Definitively, there exist no binary output formatting specifier.
>
> The big problem is, that current C++ IO behaviour is rather
> completely expressed in terms of stdio equivalents, e.g.
> Table 55 (Integer conversions) of the current official standard
> 14882:2003:
>
> State                      stdio equivalent
> basefield == oct            %o
> basefield == hex           %X
> basefield == 0               %i
> [..]
>
> and there exists no corresponding stdio *format* equivalent
> for base-2 output. Yes, it is possible to create base-2
> output via pure stdio equivalents, namely strto(u)l(l) and I
> guess that it is possible to specify it in this way (Even the
> C99 format specifiers are described in terms of strto(u)l), but
> I assume that this was the reason for not providing such a
> basefield or manipulator.
>
> Greetings from Bremen,
>
> Daniel Kr      gler
>
> ---
> [ comp.std.c++ is moderated.  To submit articles, try just posting with ]
> [ your news-reader.  If that fails, use mailto:std-...@ncar.ucar.edu    ]
> [              --- Please see the FAQ before posting. ---               ]
> [ FAQ:http://www.comeaucomputing.com/csc/faq.html                     ]

Must everyone define a binary output when using it?


---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: "=?gb2312?B?RGFuaWVsIEtyqLlnbGVy?=" <daniel.kruegler@googlemail.com>
Date: Wed, 28 Mar 2007 13:09:11 CST
Raw View
godwater@gmail.com schrieb:

> Must everyone define a binary output when using it?

Sorry, I lost you totally. What did you mean?

Greetings from Bremen,

Daniel Kr      gler


---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: godwater@gmail.com
Date: Thu, 29 Mar 2007 01:08:00 CST
Raw View
On 3      29      ,             3  09      , "Daniel Kr      gler" <daniel.krueg...@googlemail.com>
wrote:
> godwa...@gmail.com schrieb:
>
> > Must everyone define a binary output when using it?
>
> Sorry, I lost you totally. What did you mean?
>
> Greetings from Bremen,
>
> Daniel Kr      gler
>
> ---
> [ comp.std.c++ is moderated.  To submit articles, try just posting with ]
> [ your news-reader.  If that fails, use mailto:std-...@ncar.ucar.edu    ]
> [              --- Please see the FAQ before posting. ---               ]
> [ FAQ:http://www.comeaucomputing.com/csc/faq.html                     ]

Oh, I'm sorry. I mean that if we need implement one by ourselves when
we need output as binary format. Thanks.



---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: "James Kanze" <james.kanze@gmail.com>
Date: Thu, 29 Mar 2007 09:56:10 CST
Raw View
On Mar 28, 7:34 pm, godwa...@gmail.com wrote:
> Must everyone define a binary output when using it?

If you want to output binary, you'll have to implement it
yourself, yes.

The same is true for base 3, or base 7, of course.  But the
demand for this is definitly less:-).  Still, I don't see why
the basefield wasn't simply defined as a field (or a separate
value), with all values between 2 and 36 legal.  (In C, strtol
etc. accept these as input, and output is always easier than
input.  And in my own pre-standard implementation of iostream,
the base was a five bit field in fmtflags, with ios::dec,
ios::hex and ios::oct having the necessary values to initialize
it to 10, 16 and 8, respectively.)

--
James Kanze (GABI Software)             email:james.kanze@gmail.com
Conseils en informatique orient   e objet/
                   Beratung in objektorientierter Datenverarbeitung
9 place S   mard, 78210 St.-Cyr-l'   cole, France, +33 (0)1 30 23 00 34


---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: Gennaro Prota <gennaro.prota@yahoo.com>
Date: Sat, 31 Mar 2007 09:39:21 CST
Raw View
On Thu, 29 Mar 2007 14:52:38 GMT, Alberto Ganesh Barbati wrote:

>godw...@gmail.com ha scritto:
>>
>> Oh, I'm sorry. I mean that if we need implement one by ourselves when
>> we need output as binary format. Thanks.
>>
>
>If you don't care about performances and your numbers fit in an unsigned
>long, you can use bitset. For example:
>
>  std::cout << std::bitset<32>(53);
>
>produces
>
>  00000000000000000000000000110101
>
>(notice that the number of binary digits produced is equal to the number
>of bits specified in the template argument).
>
>The issue about performances is that operator<< is implemented by first
>converting the number to a string and then outputting the string, thus
>potentially incurring in a dynamic allocation.

Better late than never.. I think I'll make another attempt at getting
a reply for this:

  <http://google.com/group/comp.std.c++/msg/c2e71528fa98fa06>

--
Gennaro Prota.
In search of passioned C++ developers?   I'm available.
Breeze C++:  https://sourceforge.net/projects/breeze/
                    (incomplete, preview state)

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: "Steve Ward" <planet36@gmail.com>
Date: Mon, 26 Mar 2007 18:30:18 CST
Raw View
I'm curious why there is no "bin" format flag or basefield
manipulator.  There is dec (base 10), hex (base 16), and oct (base 8),
but no bin (understood to be base 2).

Is there a good reason why bin doesn't exist?  If not, then I'm
tempted to write a proposal.

I looked in the index and there is nothing named "bin" so a name
conflict can't be the reason.  Also, I don't have a copy of D&E handy,
in case the answer lies therein.


I'm referencing these sections in N2134:

27.4.2 Class ios_base
27.4.2.1.2 Type ios_base::fmtflags

27.4.5 ios_base manipulators
27.4.5.3 basefield manipulators



Steve Ward

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: "=?iso-8859-1?q?Daniel_Kr=FCgler?=" <daniel.kruegler@googlemail.com>
Date: Tue, 27 Mar 2007 12:18:47 CST
Raw View
Steve Ward schrieb:

> I'm curious why there is no "bin" format flag or basefield
> manipulator.  There is dec (base 10), hex (base 16), and oct (base 8),
> but no bin (understood to be base 2).
>
> Is there a good reason why bin doesn't exist?  If not, then I'm
> tempted to write a proposal.
>
> I looked in the index and there is nothing named "bin" so a name
> conflict can't be the reason.  Also, I don't have a copy of D&E handy,
> in case the answer lies therein.

Definitively, there exist no binary output formatting specifier.

The big problem is, that current C++ IO behaviour is rather
completely expressed in terms of stdio equivalents, e.g.
Table 55 (Integer conversions) of the current official standard
14882:2003:

State                      stdio equivalent
basefield == oct            %o
basefield == hex           %X
basefield == 0               %i
[..]

and there exists no corresponding stdio *format* equivalent
for base-2 output. Yes, it is possible to create base-2
output via pure stdio equivalents, namely strto(u)l(l) and I
guess that it is possible to specify it in this way (Even the
C99 format specifiers are described in terms of strto(u)l), but
I assume that this was the reason for not providing such a
basefield or manipulator.

Greetings from Bremen,

Daniel Kr   gler


---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]