Re: What's wrong with this code?
- From: Army1987 <army1987@xxxxxxxxx>
- Date: Sun, 30 Sep 2007 14:40:46 +0200
On Sat, 29 Sep 2007 08:43:44 -0700, xbyte wrote:
It's a problem from a book, and I can't figure it out.None. But if you replace `<< 3` with `* CHAR_BIT` and 0xFF with
4 words (4x8 bits) are packed into a 32-bit unsigned integer, and
you've gotta extract an indicated (by bytenum) word from it, AND the
following code is said to be written by a failed programmer:
int xbyte(unsigned word, int bytenum)
{
return (word >> (bytenum << 3)) & 0xFF;
}
IMHO, this is a perfect bulk of code, what's your opinion?
UCHAR_MAX (these are in <limits.h>), you don't have to know how
big the word and the bytes are.
--
Army1987 (Replace "NOSPAM" with "email")
A hamburger is better than nothing.
Nothing is better than eternal happiness.
Therefore, a hamburger is better than eternal happiness.
.
- Follow-Ups:
- Re: What's wrong with this code?
- From: Peter J. Holzer
- Re: What's wrong with this code?
- References:
- What's wrong with this code?
- From: xbyte
- What's wrong with this code?
- Prev by Date: Re: Macro for supplying memset with an unsigned char
- Next by Date: Re: Defect reports (was Re: what does this warning mean ?)
- Previous by thread: Re: What's wrong with this code?
- Next by thread: Re: What's wrong with this code?
- Index(es):