Path: utzoo!news-server.csri.toronto.edu!cs.utexas.edu!uunet!mcsun!ukc!cf-cm!cf-cm!bharat From: bharat@cf-cm.computing-maths.cardiff.ac.uk (Bharat Mediratta) Newsgroups: comp.unix.questions Subject: Re: bit mover Message-ID: <1991Mar14.135610.23380@cm.cf.ac.uk> Date: 14 Mar 91 13:56:10 GMT References: <788@llnl.LLNL.GOV> Sender: news@cm.cf.ac.uk (USENET News System) Organization: University of Wales College of Cardiff Lines: 48 In article <788@llnl.LLNL.GOV> handeli@ocfmail.ocf.llnl.gov () writes: >I need a C function which can move arbitrary >bits around from one memory location to another >with a bit offset of anything. For example, >the call might look like > >movebits(a1,ioff1,a2,ioff2,nbits) > >where a1 and a2 are char arrays >ioff1 and ioff2 are bit offsets into the >char arrays >nbits is the number of bits to move. >a1 might be source address and a2 might be >destination address. > >Anybody have such a function? DISCLAIMER: I haven't tested this, but I think it will work. /* * Off1 & Off2 are the offsets of the bit * 0 = rightmost bit. * No error correction */ movebits(src, off1, dest, off2, nbits) int *src, *dest; int off1, off2, nbits; { off1 = 1<