comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: 4-bit words
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: 4-bit words [message #5415 is a reply to message #5411] Thu, 21 December 1995 00:00 Go to previous messageGo to previous message
David S. Foster/Admin is currently offline  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
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Previous Topic: roots of polynomial on a 2d grid
Next Topic: Anyone out there?

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Thu Oct 09 07:23:14 PDT 2025

Total time taken to generate the page: 0.79849 seconds