What is the _REAL_ SunSparc1 sound-format?!?

Guy Harris auspex!guy at uunet.uu.net
Sat Jun 16 04:18:41 AEST 1990


>> I don't understand the: (tmp < 0) ? 128 - tmp : tmp; part. If I don't do
>
>You'd better use bit masks rather than arithmetics. tmp & 128 means
>something (i.e. the eighth bit  is set) and tmp & 127 means only the seven
>first bits are meaningful

The fact that the 8th bit is set just means that the value is, if
considered signed, negative, and if considered unsigned, greater than 127.

The crux of the biscuit is that he improperly declared "tmp" to be a
"char"; "getchar()" returns an "int" value that's either in the range 0
through 255 on 8-bit-byte machines, or EOF (i.e., -1).  If you stuff that
value into a "char", Bad Things happen, such as the byte '\377' being
indistinguishable from EOF on signed-char machines, or EOF turning into
255 and not comparing equal to EOF on unsigned-char machines. 

Another Bad Thing is that bytes in the unsigned range 128 through 255 get
turned into negative values; the "(tmp < 0) ..." glop is attempting to
compensate for that and turn them back into their proper positive values,
but declaring "tmp" to be an "int" and not getting them turned into
negative values in the first place is the proper fix.



More information about the Comp.sys.sun mailing list