Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #15168
| From | goran.pusic@gmail.com |
|---|---|
| Newsgroups | comp.lang.c++ |
| Subject | Re: how to add pad byte |
| Date | 2012-03-30 06:40 -0700 |
| Organization | http://groups.google.com |
| Message-ID | <14818156.4371.1333114842374.JavaMail.geo-discussion-forums@vbhv6> (permalink) |
| References | <12a32df5-3958-4a20-b6cf-eb6f3ddacd3e@l7g2000vbw.googlegroups.com> |
On Sunday, March 25, 2012 11:49:17 AM UTC+2, Cplusplus Programmer wrote: > Hello all, > > Suppose I need to store the binary notation of an integer value into a > char and later write it to a binary file. > However I do not know beforehand the value. So I would like to reserve > say n (with n =5) bytes for that integer. It may sound odd, however > the type of file I am going to write represents an integer in a > variable number of bytes. In this way we can store any integer value > as large we want. So, I don't know the value I am going to store, but > I have an upper limit and thus I reserve 5 bytes for it. But now when > I know the value, I discover I only need 3 bytes. Now I have to add 2 > pad bytes. Can someone explain to me how to add pad bytes ? Is this > binary notation 0000 a pad byte ? So if I had char[2] = 0; then > char[2] is a pad byte ? What "pad" is depends on the file format. Depending on the situation, padding might be octet 0, or '0', or ' '. You need to find out, from the definition of file format, what the pad is. The rest of your question is trivial: reserve space, fill "useful" part with your number, fill the rest with padding. Goran.
Back to comp.lang.c++ | Previous | Next — Previous in thread | Find similar | Unroll thread
how to add pad byte Cplusplus Programmer <cplusplusprogrammer73@gmail.com> - 2012-03-25 02:49 -0700
Re: how to add pad byte Jorgen Grahn <grahn+nntp@snipabacken.se> - 2012-03-25 11:40 +0000
Re: how to add pad byte Cplusplus Programmer <cplusplusprogrammer73@gmail.com> - 2012-03-25 10:00 -0700
Re: how to add pad byte scott@slp53.sl.home (Scott Lurndal) - 2012-03-25 17:58 +0000
Re: how to add pad byte Cplusplus Programmer <cplusplusprogrammer73@gmail.com> - 2012-03-25 11:41 -0700
Re: how to add pad byte Richard Damon <news.x.richarddamon@xoxy.net> - 2012-03-25 14:51 -0400
Re: how to add pad byte Cplusplus Programmer <cplusplusprogrammer73@gmail.com> - 2012-03-25 13:44 -0700
Re: how to add pad byte Cplusplus Programmer <cplusplusprogrammer73@gmail.com> - 2012-03-25 13:46 -0700
Re: how to add pad byte Richard Damon <news.x.richarddamon@xoxy.net> - 2012-03-25 19:25 -0400
Re: how to add pad byte Jorgen Grahn <grahn+nntp@snipabacken.se> - 2012-03-25 19:49 +0000
Re: how to add pad byte "Fred Zwarts \(KVI\)" <F.Zwarts@KVI.nl> - 2012-03-26 10:05 +0200
Re: how to add pad byte jgk@panix.com (Joe keane) - 2012-03-29 23:05 +0000
Re: how to add pad byte goran.pusic@gmail.com - 2012-03-30 06:40 -0700
csiph-web