From: Robert A Duff <bobduff@shell01.TheWorld.com>
Subject: Re: Enumeration representation clause surprise.
Date: Sun, 15 Jun 2008 15:33:03 -0400
Date: 2008-06-15T15:33:03-04:00 [thread overview]
Message-ID: <wcc3ane334g.fsf@shell01.TheWorld.com> (raw)
In-Reply-To: 4f5f512a-36e6-466e-a5a9-5f26857841f8@w4g2000prd.googlegroups.com
Adam Beneschan <adam@irvine.com> writes:
>...So
> what number is stored in a 0-bit data item?
Zero.
An n-bit field is either signed or unsigned.
When you load the field into a register, you
take all the bits and add copies of the sign bit on the left
(for signed) or zeros on the left (for unsigned).
A 0-bit field must be unsigned (there's no sign bit!).
So you take nothing, and add 32 zero bits on the left
(on a 32-bit machine).
Or you could think of it as an infinitely-long string of bits -- you
sign extend or zero extend infinitely on the left to get the value.
Then of course you can bias that 0 by anything -- range 100..100
can be stored in a zero-bit unsigned bitfield, biased by 100.
(Or is that -100?)
>...I suppose you could
> arbitrarily decide it's zero (which would make some sense
> mathematically)
Yes, I think so.
>... but it seems more commonsensical to say that nothing
> is stored there because there ain't no bits to store anything in.
But that view requires a special case.
The natural unsigned range for n bits, where n >= 0,
is 0..(2**n)-1. Which is 0..0 when n = 0.
The natural signed (2's complement) range for n bits, where n > 0,
is -(2**(n-1))..(2**(n-1))-1. Which makes no sense
if n = 0, because we don't want to mess around with
negative exponents (fractions) -- we're talking about
integer ranges.
- Bob
next prev parent reply other threads:[~2008-06-15 19:33 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-06-11 11:38 Enumeration representation clause surprise Markus Schoepflin
2008-06-11 12:30 ` christoph.grein
2008-06-11 12:56 ` Markus Schoepflin
2008-06-11 13:08 ` christoph.grein
2008-06-11 13:28 ` Samuel Tardieu
2008-06-11 13:48 ` Markus Schoepflin
2008-06-11 13:56 ` Samuel Tardieu
2008-06-11 14:58 ` Adam Beneschan
2008-06-11 15:23 ` Markus Schoepflin
2008-06-12 2:37 ` Randy Brukardt
2008-06-12 2:37 ` Randy Brukardt
2008-06-11 15:56 ` Samuel Tardieu
2008-06-11 19:10 ` Adam Beneschan
2008-06-11 19:59 ` Niklas Holsti
2008-06-12 1:16 ` tmoran
2008-06-12 8:27 ` christoph.grein
2008-06-12 8:45 ` Markus Schoepflin
2008-06-12 16:43 ` Mike Silva
2008-06-12 18:41 ` Markus Schöpflin
2008-06-12 20:10 ` Mike Silva
2008-06-12 20:52 ` Simon Wright
2008-06-12 23:36 ` Mike Silva
2008-06-13 5:49 ` Simon Wright
2008-06-13 7:21 ` Keith Thompson
2008-06-13 13:31 ` Mike Silva
2008-06-13 14:45 ` Markus Schoepflin
2008-06-13 17:52 ` Keith Thompson
2008-06-13 9:14 ` Jean-Pierre Rosen
2008-06-12 19:05 ` richtmyer
2008-06-12 21:26 ` Samuel Tardieu
2008-06-12 22:42 ` Adam Beneschan
2008-06-13 7:11 ` Samuel Tardieu
2008-06-13 8:27 ` christoph.grein
2008-06-13 16:21 ` Adam Beneschan
2008-06-15 19:33 ` Robert A Duff [this message]
2008-06-16 14:50 ` Adam Beneschan
2008-06-16 19:18 ` Robert A Duff
2008-06-17 6:03 ` christoph.grein
2008-06-17 7:22 ` christoph.grein
2008-06-13 8:24 ` Peter Hermann
2008-06-13 14:47 ` Samuel Tardieu
2008-06-14 11:48 ` John B. Matthews
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox