accessing a integer of size 4bytes in a 16bit architecture

K

Keith Thompson

Tom St Denis said:
yeah yeah yeah I get it. It's all academic anyways since essentially
all platforms nowadays don't do that. All of ARM, PPC, MIPS, and x86
[which makes up the vast majority of 32/64-bit processors] have at
least a 32-bit range for signed longs.

But I guess my bad for not having the ISO spec memorized in all
aspects.

Bad? Not at all. You missed something and didn't get the joke. It's
not a big deal; why make it one?
 
T

Tom St Denis

yeah yeah yeah I get it.  It's all academic anyways since essentially
all platforms nowadays don't do that.  All of ARM, PPC, MIPS, and x86
[which makes up the vast majority of 32/64-bit processors] have at
least a 32-bit range for signed longs.
But I guess my bad for not having the ISO spec memorized in all
aspects.

Bad?  Not at all.  You missed something and didn't get the joke.  It's
not a big deal; why make it one?

I DON'T KNOW!!! :)

Is the damn week over yet? ...

Tom
 
K

Keith Thompson

Keith Thompson said:
Tom St Denis said:
yeah yeah yeah I get it. It's all academic anyways since essentially
all platforms nowadays don't do that. All of ARM, PPC, MIPS, and x86
[which makes up the vast majority of 32/64-bit processors] have at
least a 32-bit range for signed longs.

But I guess my bad for not having the ISO spec memorized in all
aspects.

Bad? Not at all. You missed something and didn't get the joke. It's
not a big deal; why make it one?

I now realize I somehow read "my bad" as "I'm bad" and therefore
thought you were overreacting.

My bad.
 
N

Nobody

long has to be at least 32 bits
unsigned long has to be at least 32 bits.
long can be as little as 31.9999999996640964- bits.
While I realize you're trying to be funny, long still represents 2^32
values, even though the absolute maximum is half that of an unsigned
long.  So no, a long MUST be at least 32 bits.

Sign-bit representation is allowed, so it may only be able to represent
2^32-1 distinct values. log[2](2^32-1) = 31.9999999996640964...

You still need a bit of entropy for the sign bit.

Sign-bit representation means that you have distinct bit patterns for -0
and +0, but these may be indistinguishable from within C (i.e. they cannot
be distinguished without relying upon UB or possibly IDB).
And anyways ... 0
to 2^31 - 1 inclusive is 2^31 values, there are 2^31 negative values.
That's 2^32 unique values.

Not with sign-bit representation. There are 2^31-1 negative values,
2^31-1 positive values, and two bit patterns for zero, meaning 2^32-1
distinct values (positive zero and negative zero aren't distinct).
Maybe I'm not getting your math failures?

Clearly.
 
T

Tim Rentsch

Tom St Denis said:
In


On Wed, 21 Oct 2009 04:50:20 -0700, Tom St Denis wrote:
long has to be at least 32 bits
unsigned long has to be at least 32 bits.
long can be as little as 31.9999999996640964- bits.
While I realize you're trying to be funny, long still represents
2^32 values, even though the absolute maximum is half that of an
unsigned long. So no, a long MUST be at least 32 bits.
Sign-bit representation is allowed, so it may only be able to
represent 2^32-1 distinct values. log[2](2^32-1) =
31.9999999996640964...
You still need a bit of entropy for the sign bit. And anyways ... 0
to 2^31 - 1 inclusive is 2^31 values, there are 2^31 negative
values. That's 2^32 unique values.
Maybe I'm not getting your math failures?

Maybe you're not getting *your* math failures - or rather, your C
failures. LONG_MIN can be as "high" as -2147483647; on such a system,
there are only 4294967295 distinct values, not 4294967296. That is
the whole point of the joke.

Now I know why I stay out of asinine C threads...

Whatever, it's all academic anyways.

Sorry, my humor does tend towards the understated
at times. I could have put in a smiley, but then
(IMO anyway) the joke wouldn't have been as funny.
Of course some people may think it wasn't that funny
anyway.... (practices ducking tomatoes)
 
R

robertwessel2

 > yeah yeah yeah I get it.  It's all academic anyways since essentially
 > all platforms nowadays don't do that.  All of ARM, PPC, MIPS, and x86
 > [which makes up the vast majority of 32/64-bit processors] have at
 > least a 32-bit range for signed longs.
Actually having a trap representation there can be pretty helpful in
detecting unassigned variables.  And, of course, negation always works.

Useful or not, most platforms can represent -2^31 in a long.  2^31 +
2^31 is 2^32.  That I get that the spec says they need only support
-2^31 + 1 means I'm ok with getting schooled about my earlier
comments.  But I stand by the fact it's an academic distinction.

It's like arguing about CHAR_BIT=8.  Sure, don't ever say it's "equal
to 8" but you can pretty much guarantee that on a platform that was
fab'ed in the last 20 years and ISN'T A PIC of some sort, that it's a
sure thing.


Actually there are a fair number of (quite current) DSPs where
CHAR_BIT is not 8. Usually 16, 24 or 32.
 
M

Morris Keesan

Actually there are a fair number of (quite current) DSPs where
CHAR_BIT is not 8. Usually 16, 24 or 32.

And, since Tom extended his range to "the last 20 years", and this
is only 2009, I think he's wrong there, as well. I'm pretty sure
that BBN was still manufacturing a few C70 machines when I left
there in 1990.
(Unix host, CHAR_BIT == 10, sizeof(int) == 2, sizeof(long) == 4).
Programming that, and porting other people's code to it [primarily
VAX-originated code] taught me loads about portability.

("A PIC of some sort"? acronymfinder.com returned 130 meanings for PIC,
with a note that there are 250 more in their Acronym Attic. Which meaning
is intended here?
 
R

robertwessel2

("A PIC of some sort"?  acronymfinder.com returned 130 meanings for PIC,
with a note that there are 250 more in their Acronym Attic.  Which meaning
is intended here?


Undoubtedly he meant one of the Microchip lines of microcontrollers.
This includes a number of quite different ISAs implemented in a vast
array of products sold under the PIC10, PIC12, PIC14, PIC16, PIC17,
PIC18, PIC24, dsPIC and PIC32 headings.

Most of the smaller models present considerable weirdness from a
programmer's perspective (the smallest PIC10s have 512 12-bit words of
instruction ROM, 32 8-bit bytes of "RAM", a two level call stack, and
a quite unusual ISA), while PIC32 is an implementation of MIPS. And
yes, there are C (or C-like) compilers for all of these.
 
R

robertwessel2

Undoubtedly he meant one of the Microchip lines of microcontrollers.
This includes a number of quite different ISAs implemented in a vast
array of products sold under the PIC10, PIC12, PIC14, PIC16, PIC17,
PIC18, PIC24, dsPIC and PIC32 headings.

Most of the smaller models present considerable weirdness from a
programmer's perspective (the smallest PIC10s have 512 12-bit words of
instruction ROM, 32 8-bit bytes of "RAM", a two level call stack, and
a quite unusual ISA), while PIC32 is an implementation of MIPS.  And
yes, there are C (or C-like) compilers for all of these.


Except possibly the DSP PICs (the PIC24s and dsPICs - which I've never
worked with), all the C compilers I've seen for PICs use 8 bit chars,
so Tom is complaining about the wrong line of weird microcontrollers
anyway...
 
E

Erik Trulsson

Tom St Denis said:
long has to be at least 32 bits
unsigned long has to be at least 32 bits.
long can be as little as 31.9999999996640964- bits.
While I realize you're trying to be funny, long still represents 2^32
values, even though the absolute maximum is half that of an unsigned
long.  So no, a long MUST be at least 32 bits.

Sign-bit representation is allowed, so it may only be able to represent
2^32-1 distinct values. log[2](2^32-1) = 31.9999999996640964...

You still need a bit of entropy for the sign bit. And anyways ... 0
to 2^31 - 1 inclusive is 2^31 values, there are 2^31 negative values.

No, there are only 2^31-1 negative values with a sign-bit representation - just
as many as the positive values. Add one for the 0 value (which is neither positive
nor negative) and you get a total of (2^31-1) + (2^31-1) + 1 distinct values.

That's 2^32 unique values.

That's 2^32-1 unique values.

(For a 32-bit number with sign-magnitude representation there are 2^32
possible bit-patterns, but since there will be two different representations
of the value 0 there will only be 2^32-1 unique values.)

Maybe I'm not getting your math failures?

Or maybe it is you who is failing at math.
 
R

Richard Bos

Tim Rentsch said:
The point of the joke is that long might have only (2**32 - 1) values
rather than (2**32) values.

This may come as a surprise to someone who has studied, rather than
used, computer programming, but in C, bits are discrete. Next time, try
a joke that works.

Richard
 
S

Squeamizh

This may come as a surprise to someone who has studied, rather than
used, computer programming, but in C, bits are discrete. Next time, try
a joke that works.

I couldn't agree with you more; he really needs to get his head out of
academia land. Here in the real world, a joke must contain only
factual information when taken entirely literally.
 
J

James Kuyper

Richard said:
This may come as a surprise to someone who has studied, rather than
used, computer programming, but in C, bits are discrete.

It's precisely the fact that makes it a joke. If it weren't for that
fact, it would simply be a perfectly serious and meaningful statement.
 
B

bartc

Richard Bos said:
This may come as a surprise to someone who has studied, rather than
used, computer programming, but in C, bits are discrete.

So are people. But you can still talk about 2.5 children per family.
 
B

Bruce Cook

Tom said:
yeah yeah yeah I get it. It's all academic anyways since essentially
all platforms nowadays don't do that. All of ARM, PPC, MIPS, and x86
[which makes up the vast majority of 32/64-bit processors] have at
least a 32-bit range for signed longs.

Actually having a trap representation there can be pretty helpful in
detecting unassigned variables. And, of course, negation always works.

Useful or not, most platforms can represent -2^31 in a long. 2^31 +
2^31 is 2^32. That I get that the spec says they need only support
-2^31 + 1 means I'm ok with getting schooled about my earlier
comments. But I stand by the fact it's an academic distinction.

The distinction was "real" enough and caught enough programmers (who were
relying on specific overflow characteristics) that autoconf grew a standard
test for 1's compliment architectures. From Memory IBM and CDC used to
favour 1's compliment architectures and were common enough that they needed
to be cater for in the GNU tools chain.

Bruce
 
T

Tim Rentsch

This may come as a surprise to someone who has studied, rather than
used, computer programming, but in C, bits are discrete. Next time, try
a joke that works.

I'm sorry you didn't find it more entertaining. All
I can say is different people have different senses
of humor.
 
G

Guest

|>
|> >>       Can you please tell me how to access a integer of size 4bytes in
|> >> a 16bit architecture?
|>
|> > long has to be at least 32 bits
|>
|> unsigned long has to be at least 32 bits.
|> long can be as little as 31.9999999996640964- bits.
|
| While I realize you're trying to be funny, long still represents 2^32
| values, even though the absolute maximum is half that of an unsigned
| long. So no, a long MUST be at least 32 bits.

OTOH, the maximum for long, cast to unsigned long, and multiplied by two,
is still less than the maximum for unsigned long.

if ( 2U * (unsigned long) LONG_MAX < ULONG_MAX ) puts( "woot!" );

Still requires 32 bits in all cases for these common architectures.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top