Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #15063

Re: how to add pad byte

From Richard Damon <news.x.richarddamon@xoxy.net>
Newsgroups comp.lang.c++
Subject Re: how to add pad byte
Date 2012-03-25 19:25 -0400
Organization A noiseless patient Spider
Message-ID <jko9gj$52n$1@dont-email.me> (permalink)
References (2 earlier) <c16c1a24-19d6-4874-9e1f-1c3d81d70ba0@z31g2000vbt.googlegroups.com> <s1Jbr.30044$Jl3.5176@news.usenetserver.com> <fcb0e7be-0eb7-4c7a-badf-7c3a8845b6d4@db5g2000vbb.googlegroups.com> <jknpf3$55n$1@dont-email.me> <8d95fadb-5b23-43a0-b290-3c24c9df2b7e@b14g2000vbz.googlegroups.com>

Show all headers | View raw


On 3/25/12 4:44 PM, Cplusplus Programmer wrote:

> Hi
> 
> So, if I understand correctly. add 0s when padding positive values and
> add is when padding negative values, am I correct ?
> 
> 
> "The only difference between these bits and the "needed" bits
> is that needed 0's have a one bit above them. Ultimately, the program
> is
> just going to treat all of the bits a "value" and none as "padding"."
> 
> I still don't understand this bit. What do you mean by the "needed 0's
> have a one bit above them" ? What is the one bit above them ? And what
> do you mean by "..bits a "value" and none as "padding". What is a
> none ? Sorry if this sound like a silly question.
> 
> regards,
> 
> cppp

As an example (with bits not bytes)

The number 5 in binary is 101,
If we need to express is in two complement, where the top bit is a sign
bit it becomes 0101

The first is a "3 bit value", the second a "4 bit value".

In the computer, we normally don't deal with this sized value, but will
expand it by "padding" to at least 8 bits to 00000101

Note that we have just extended the leading 0 sign bit to fill the word.
For 16 or 32 bits, we would do the same thing, add enough leading bits,
matching the sign bit of the number, to fill the word. There is no REAL
difference between these padding bits and the bits that really express
value (the original 3 or 4 bits) as far at the computer is concerned.

The only practical difference is that if we did need to squish it down
to a smaller number (say a 4 bit field in some message protocol), the
fact that the number can be represented with 4 value bits, and the rest
are "just padding", says it will fit in a 4 bit field.

Thus we don't really need to distinguish "Value" from "Padding"

This use of padding also doesn't mesh with how the language standard
uses the term. To the standard, a number storage format that uses
padding, has some bits that NEVER contribute to the numbers value. For
example, a machine might for some reason want two word long integers to
be stored in a manner where the lower word sign bit always matches the
upper words sign bit or is always 0 due to the way the hardware works
(you don't tend to find this on modern machines, but things like this
did happen on ancient machines). For the 2 word format, the top bit on
the lower word would be considered "padding" and not a value bit.

By this terminology, all 5 bytes of your number (even when the number is
small) are "value" bits, as they affect the value of the number.

Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


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