CBFalconer wrote:
>
> pete wrote:
> > CBFalconer wrote:
> > > Rob Williscroft wrote:
> > > > curium wrote:
> > > >
> > > > > I need to copy bits 0-6 from a byte into bits 0-6 of a word.
> > > > > then i need to copy bits 0-6 from another byte
> > > > > into bits 7-14 of this word.
> > > > >
> > > > > I am going gray from messing around with AND, OR, >> and <<
> > > > > operators. I hope the collective audience of this group can
> > > > > point out an obvious solution to this problem so that i can
> > > > > kick myself for not seeing the obvious.
> > > > >
> > > > > The main problem i am experiencing is preserving the LO byte
> > > > > of the word when copying from the 2nd byte.
> > > >
> > > > unsigned merge( unsigned char lo, unsigned char hi )
> > > > {
> > > > unsigned result = static_cast< unsigned >(lo) & 0x3F;
> > > >
> > > > result |= ( static_cast< unsigned >(hi) & 0x3F ) << 6;
> > > > return rsult;
> > > > }
> > >
> > > Because some idiot cross posted to c.l.c and c.l.c++, you have
> > > posted something that is not applicable on c.l.c. So lets change
> > > the function body to be valid C, and hope it is still valid C++
> > > 
> > >
> > > unsigned int result;
> > >
> > > result = ((hi & 0x3f) << 6) | (lo & 0x3f);
> > > return result;
> > >
> > > These values can never cause an integer overflow. There is no
> > > such thing as an AND or an OR operator.
> >
> > I don't understand what you mean by
> > "There is no such thing as an AND or an OR operator."
>
> The operators are || and &&,
> unless you #include <iso646.h>, when
> the macros 'or' and 'and' expand to those anyway.
I'm having a very hard time parsing that sentence.
You're saying that when you #include <iso646.h>,
then || and && aren't the operators, but that when you
don't #include <iso646.h>, then they are the operators.
I'm even more confused about what you're saying now.
What do you mean by "The", in "The operators" ?
There's no || or && in the posted code,
so you must mean that those operators have been previously
referred to in the text of this thread.
*Which* operators are || and && ?
The ones which there are no such things as ?
Is your objection that he did not precisely specify
"bitwise AND operator"
and
"bitwise inclusive OR assignment operator"
?
--
pete