to calculate bitsize of a byte

D

david ullua

I thought your reply was generated automatically, when someone didn't
quote other's word to reply, the system post a reply to remind. hahaha

Default User 写é“:
 
D

Default User

david said:
I thought your reply was generated automatically, when someone didn't
quote other's word to reply, the system post a reply to remind. hahaha

Please don't top-post. Your replies belong following or interspersed
with properly trimmed quotes. See almost every other message on the
newsgroup.




Brian
 
R

Richard G. Riley

Please don't top-post. Your replies belong following or interspersed
with properly trimmed quotes. See almost every other message on the
newsgroup.




Brian

I suspect that you are a very good C programmer : either that or
looking for guidance or help in this NG. Nothing wrong there.

Tiring of repeatedly seeing OLD posts reignited because the likes of
you reply yet another damn "etiquette" guide, I had a quick look at
google.

http://tinyurl.com/ekv6p

Interestingly it would appear that the only thing you do is post
reprimands or repeat the bleeding obvious.

How about a compromise? If the post is less than a day old OR noone
got there before you, THEN post your little guidelines.
 
M

Mark McIntyre

Tiring of repeatedly seeing OLD posts reignited because the likes of
you reply yet another damn "etiquette" guide,

you can always killfile him. It'd be your loss, not his. :)
I had a quick look at google.

http://tinyurl.com/ekv6p

Google may be great, but it doesn't archive everything.
How about a compromise? If the post is less than a day old OR noone
got there before you, THEN post your little guidelines.

I think you need to remember that usenet is NOT a synchronous
mechanism., There's no way to know if someone "got there before you",
since you may see their post already, but the OP may never see it, or
vice-versa.

Its trickier than you think.
Mark McIntyre
 
R

Richard Bos

CBFalconer said:
Don't forget the inner satisfaction gained by restricting knowledge
from the unwashed. Oooh, it's positively orgasmic.

Personally, I've always done it because it makes my diminutive coding
skills look better than those of the newbie with four decades of C
experience.

Richard
 
D

Dave Thompson

unsigned i, c;
unsigned char *bp1, *bp2;
i = 0;
bp1 = bp2 = (unsigned char *)&i;
bp1++; /* point to second byte */
bp2 += sizeof i - 1; /* point to second-to-last byte */
for (c = 0; *bp1 == 0 && *bp2 == 0; c++)
i = 1u << c;
This works for both big- and little-endian architectures, as far as I
can see, because it tests when the shift operator alters the second
or penultimate bytes. I don't offhand see a way for a conforming
implementation (where sizeof(unsigned) > 1) to produce the wrong
answer.
PDP-11 "middle-endian" (hi.lo, hi.hi, lo.lo, lo.hi) gives 0.

Although it could conform only to C90 because it couldn't support a
single 64K-1B object together with an invocation of main(). said:
Extending the program to handle the case where sizeof(unsigned) is 1
is left as an exercise for the reader.

Shifting or otherwise popcounting (unsigned char)-1 is more reliable
and simpler/clearer to boot.

- David.Thompson1 at worldnet.att.net
 
C

Charles Krug

What are you referring to? The context provided is insufficient.

The OP wanted bits per byte. C defines (freely speaking) char to be
"one byte" (IANALL).

So CHAR_BIT is the number of bits in a byte.

IANALL, not valid in Vermont, Puerto Rico, the US Virgin Islands, or
where prohibited by ARINC 653
 
C

Charles Krug

Charles Krug said:


No such animal. Care to try again?

Is CHAR_BIT not what the OP is after?

I'm not aware that C offers us any other definition for "byte", though
IANALL.

I'm fairly certain that the difficulties inherent in transferring data
from a TI 'c40 to a PPC 704 over VMEBus (each has a distinct idea of the
size of a "byte") are OT.
 
K

Keith Thompson

Charles Krug said:
The OP wanted bits per byte. C defines (freely speaking) char to be
"one byte" (IANALL).

So CHAR_BIT is the number of bits in a byte.

Yes, CHAR_BIT is by definition the number of bits in a byte, which is
exactly what the OP was asking about. The thread wandered into a
discussion of how to compute CHAR_BIT without actually using the
CHAR_BIT macro. There are several ways to do this, none of them
useful if CHAR_BIT is available, but it's an interesting exercise.
(It could also be useful in the unlikely event that CHAR_BIT is
defined incorrectly; this could possibly happen if the compiler and
<limits.h> are out of sync.)
 
J

Jordan Abel

The OP wanted bits per byte. C defines (freely speaking) char to be
"one byte" (IANALL).

Out of curiosity, what is IANALL supposed to disclaim? How does one
become qualified as such?
 
R

Richard Heathfield

Jordan Abel said:
Out of curiosity, what is IANALL supposed to disclaim?

I Am Not A Language Lawyer.
How does one become qualified as such?

By being a language-lawyer-in-training (because it is invariably used with
an implied "but...").
 
C

Charles Krug

Jordan Abel said:


I Am Not A Language Lawyer.


By being a language-lawyer-in-training (because it is invariably used with
an implied "but...").

Around here, I use to disclaim my lack of accuracy.

In this case I saw someone who thought it might be useful to have a sort
of "roundish" thing that he could use to roll things around, and I was
trying to point out the prefectly good wheel over in the corner.

(freely speaking) and IANALL in this case 'cuz I wasn't giving the
precise definition of a byte--please don't use what I say to write your
own compiler--but something Good Enough for many purposes, including IMO
the issue at hand.
 

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

Forum statistics

Threads
474,176
Messages
2,570,948
Members
47,500
Latest member
ArianneJsb

Latest Threads

Top