473,899 Members | 4,308 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

to calculate bitsize of a byte

I am reading "Joel on Software" these days, and am in stuck with the
question of "how to calculate bitsize of a byte" which is listed as one
of the basic interview questions in Joel's book. Anyone could give some
ideas?I am expecting your reply.
David.

Feb 21 '06
96 5006
On 2006-03-04, Richard Heathfield <in*****@invali d.invalid> wrote:
Charles Krug said:
On 2006-03-03, Dave Thompson <da************ *@worldnet.att. net> wrote:
On 22 Feb 2006 02:30:54 GMT, mw*****@newsguy .com (Michael Wojcik)
wrote:

unsigned i, c;
unsigned char *bp1, *bp2;


Why not just use CHAR_BITS from limits.h?


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.

Mar 4 '06 #91
Charles Krug <cd****@aol.com > writes:
On 2006-03-04, Michael Mair <Mi**********@i nvalid.invalid> wrote:
Charles Krug schrieb:
On 2006-03-03, Dave Thompson <da************ *@worldnet.att. net> wrote:

On 22 Feb 2006 02:30:54 GMT, mw*****@newsguy .com (Michael Wojcik)
wrote:

> unsigned i, c;
> unsigned char *bp1, *bp2;

Why not just use CHAR_BITS from limits.h?

Just asking
8-)


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.


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.)

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Mar 4 '06 #92
On 2006-03-04, Charles Krug <cd****@aol.com > wrote:
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?
Mar 5 '06 #93
Jordan Abel said:
On 2006-03-04, Charles Krug <cd****@aol.com > wrote:
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?


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...").

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Mar 5 '06 #94
Charles Krug said:
On 2006-03-04, Richard Heathfield <in*****@invali d.invalid> wrote:
Charles Krug said:
Why not just use CHAR_BITS from limits.h?


No such animal. Care to try again?


Is CHAR_BIT not what the OP is after?


Yes. No S.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Mar 5 '06 #95
On 2006-03-05, Richard Heathfield <in*****@invali d.invalid> wrote:
Jordan Abel said:
On 2006-03-04, Charles Krug <cd****@aol.com > wrote:
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?


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...").


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.

Mar 5 '06 #96
On 2006-03-05, Richard Heathfield <in*****@invali d.invalid> wrote:
Charles Krug said:
On 2006-03-04, Richard Heathfield <in*****@invali d.invalid> wrote:
Charles Krug said:

Why not just use CHAR_BITS from limits.h?

No such animal. Care to try again?


Is CHAR_BIT not what the OP is after?


Yes. No S.


Gotta get that tire fixed. It's hissing.

Mar 5 '06 #97

This thread has been closed and replies have been disabled. Please start a new discussion.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.