🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: net.lang.mod2
Article #493

Re: Bit stripping

#493
From: Charles Haynes
Date: Mon, 04 Aug 1986 22:02
27 lines
1595 bytes
Stripping high order bits via the MOD operator is neither fast nor reliable.

Unfortunately, modula-2 implementations differ on whether ORD(ch) can be
negative or not, and how MOD operates on negative numbers. Secondly, MOD is
usually equivalent to divide in cost, though many compilers optimize for DIV
and MOD by powers of two.

Mike Powell's modula-2 provides a module called "BitOperations" that will let
you do bit AND, which would be fine, or in many cases an IF would be
reasonable. IE. 

IF ORD(ch) >= 128 THEN ch := CHR(ORD(ch)-128); END;
 
or

IF ORD(ch) < 0 THEN ch := CHR(ORD(ch)+128); END;

If you are willing to use machine dependent code, instead of reading into a
buffer of chars, you could read into an array of things which looked like:

BitChar = RECORD parity: BOOLEAN; ch: [0..127]; END;

Then use the ch fields, this assumes your modula-2 compiler allows some kind
of bit level control of record layout. Warning: this kind of code can often
be slower than the naive "IF" statement used above. Know what you are doing!

	-- Charles
Technical Details
Message-ID: <8608042202.AA08957@vulcan.DEC.COM>
Path: arc1-ca.pugleaf.net!utzoo!mnetor!seismo!lll-crg!nike!ucbcad!ucbvax!DECWRL.DEC.COM!haynes

Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: arc1-ca.pugleaf.net!utzoo!mnetor!seismo!lll-crg!nike!ucbcad!ucbvax!DECWRL.DEC.COM!haynes
From: haynes@DECWRL.DEC.COM (Charles Haynes)
Newsgroups: net.lang.mod2
Subject: Re: Bit stripping
Message-ID: <8608042202.AA08957@vulcan.DEC.COM>
Date: Mon, 4-Aug-86 18:02:20 EDT
Article-I.D.: vulcan.8608042202.AA08957
Posted: Mon Aug  4 18:02:20 1986
Date-Received: Tue, 5-Aug-86 23:17:27 EDT
Sender: daemon@ucbvax.BERKELEY.EDU
Organization: The ARPA Internet
Lines: 27