More Re: its in the 3s.....

Ken Hancock hancockks at y...
Mon, 19 Nov 2001 19:15:20 -0000


--- In ExtractStream@y..., Dale Reed <daler@n...> wrote:
> Ken Hancock wrote:
> 
> > --- In ExtractStream@y..., Dale Reed <daler@n...> wrote:
> > > > > From Tyconvert:
> > > > >
> > > > > unsigned long size = (((p[0]<<8) | p[1])<<4) | (p[2]>>4);
> 
> 
> ES .03:
> 
> > > > size = ((*p)[0]<<12 | (*p)[1])<<4 | ((*p)[2]>>4);
> 
> ^---------------------^
> 
> 
> > I'm not rusty on bit shifting -- I do it every day. Tyconvert 
uses << 8 
> > on p[0]
> > then << 4 on BOTH p[0] and p[1] which is equivalent to << 12 on p
[0]. Both
> > ES and TyConvert are the same -- people just misread the 
parentheses.
> > 
> But check out the ES .03 vs Tyconvert (above). ExtractStream
> uses 12 on the first then shifts 4 again. Thats 16, right? 
Tyconvert
> and Splitstream seem to have it correct, whereas ES doesn't. I 
outlined
> the matching () above for clarity. I double checked my es .03c 
source code
> from cvs on this as well?

The code you quoted above doesn't match what I see in ExtractStream. 
Did you just transcribe things differently? 

>From ExtractStream 0.3 CVS tree, lines 326 & 355:

TyStream[j].size = buf[p] << 12 | buf[p+1] << 4 | buf[p+2] >> 4;

This is equivalent to

Tystream[j].size = (buf[p] << 12) | (buf[p+1] << 4) | (buf[p+2] >> 4);

SHIFT operators have higher precedence than | operators. That's why 
I prefer added parentheses because I don't necessarily remember that 
AND is higher precedence than OR, let alone all the other operators.