Re: 4-bit words [message #5415 is a reply to message #5411] |
Thu, 21 December 1995 00:00   |
David S. Foster/Admin
Messages: 14 Registered: May 1995
|
Junior Member |
|
|
orbach@rockvax.rockefeller.edu (Darren Orbach) wrote:
>
> I have a file that consists of a 256*256 array of 4-bit
> words created in another application, written as a binary
> file. I need to manipulate this array by shifting these
> 4-bit elements to the right by various amounts, and wrapping
> around to the other side of the array. However, since the
> smallest data type in WAVE or IDL is a full byte, I don't see
> a straightforward way to do this. Any suggestions?
I think I would write a routine that reads in the data two
elements (8 bits) at a time, then extract the two elements
from the byte, and puts these two bytes into a
corresponding 256x256 array of bytes; then manipulate
this byte array.
Given a byte of data stored in 'value':
val = value
lo = 0B
for i = 0, 3 do begin
higher_bit = 2L ^ long(i+1)
rem = val mod higher_bit
if (rem ne 0) then begin
lo = lo + 2L ^ long(i)
val = val - rem
endif
endfor
hi = 0B
for i = 4, 7 do begin
higher_bit = 2L ^ long(i+1)
rem = val mod higher_bit
if (rem ne 0) then begin
hi = hi + 2L ^ long(i-4)
val = val - rem
endif
endfor
This *should* give the lower and upper halves of the original byte,
as two byte values, 'lo' and 'hi'. I've tested this and it seems
to work. But hey, my job description says that my programming
only has to be 90% accurate!
Wouldn't it be nice if IDL had bitwise operators!
Dave Foster
foster@bial6.ucsd.edu
|
|
|