bitwise operations 
Author Message
 bitwise operations

does REXX support bitwise operations?  For example, if the RESULT
contains the following string (ascii string representation of HEX):

    C1242C0002010001838000
what is the correct way to test the low order bit of the second byte
(First byte = C1; second byte = 24; etc.....)

Thanks.

Regards,
Marigowda Divya
GSOFT



Fri, 03 Sep 1999 03:00:00 GMT  
 bitwise operations

Quote:
> does REXX support bitwise operations?  For example, if the RESULT
> contains the following string (ascii string representation of HEX):

>     C1242C0002010001838000
> what is the correct way to test the low order bit of the second byte
> (First byte = C1; second byte = 24; etc.....)

> Thanks.

> Regards,
> Marigowda Divya
> GSOFT

Try:

  if bitand(substr(result,2,1),'01'x)='01'x then say "2nd byte low bit on"
  else say "2nd byte low bit off"


Lockheed Martin
US EPA National Computer Center



Fri, 03 Sep 1999 03:00:00 GMT  
 bitwise operations


Quote:
>does REXX support bitwise operations?  For example, if the RESULT
>contains the following string (ascii string representation of HEX):

>    C1242C0002010001838000
>what is the correct way to test the low order bit of the second byte
>(First byte = C1; second byte = 24; etc.....)

Here is one possible solution or method of testing the bit:

 idat = 'C1242C0002010001838000'x
 tdat = '0001000000000000000000'x

 ans = C2x(BitAND(idat,tdat))
 Say ans

 If ans = 0 Then
   Say 'Bit is off'
 Else
   Say 'Bit is on'



Fri, 03 Sep 1999 03:00:00 GMT  
 bitwise operations

On Monday, 97/03/17, Marigowda Divya wrote to All about "bitwise
operations" as follows:

MD> does REXX support bitwise operations?  For example, if the RESULT
MD> contains the following string (ascii string representation of
MD> HEX):
MD>
MD>     C1242C0002010001838000
MD> what is the correct way to test the low order bit of the second
MD> byte (First byte = C1; second byte = 24; etc.....)

You need to use a nest of built-in functions. Start by using SUBSTR()
to extract the byte you want, then convert it to hex with C2X(), then
convert the hex to bit with X2B() and then extract the particular bit
using RIGHT() or SUBSTR() again. The need to be coded from the inside
outwards.

E.g.

 IF RIGHT(X2B(C2X(SUBSTR(Data_bytes,2,1))),1) THEN
 DO /* It's a 1 bit */
  ...
 END
 ELSE
 DO /* It's a 0 bit */
  ...
 END

Alternatively, you can use the decimal value of the byte and modulo 2
to determine the last bit.

E.g.

 IF C2D(SUBSTR(Data_bytes,2,1))//2 THEN
 DO /* It's a 1 bit */
  ...
 END
 ELSE
 DO /* It's a 0 bit */
  ...
 END

However, this doesn't work for just any bit within the byte, only the
LSb. For any given bit within the byte you will need to use substringing
for best results.

Regards

Dave
<Team PL/I>

 * KWQ/2 1.2i * You are the Senate.  You have the power to filibuster.
--
Please remove the '$' in the from line before reply via email.
Anti-UCE filter in operation.



Fri, 03 Sep 1999 03:00:00 GMT  
 bitwise operations



Quote:
>>what is the correct way to test the low order bit of the second byte

There are lots of ways, and no subclass of "correct" ways.  You could ask
for speed, clarity, conciseness, or ???

Speed (only guessing) and conciseness:

IF C2D(SUBSTR(Chars,2,1))//2=1 THEN .....

Clarity (maybe):

IF RIGHT(C2B(SUBSTR(Chars,2,1)),1)=1 THEN ....

provided your implementation had C2B.  If not, I would go with the speed
one.




Sat, 04 Sep 1999 03:00:00 GMT  
 bitwise operations


Quote:
>does REXX support bitwise operations?  For example, if the RESULT
>contains the following string (ascii string representation of HEX):

>    C1242C0002010001838000
>what is the correct way to test the low order bit of the second byte
>(First byte = C1; second byte = 24; etc.....)

>Thanks.

>Regards,
>Marigowda Divya
>GSOFT

Seems easy:

if '0001'x=bitand('0001'x,result) then say 'On'; else say 'Off'

Chris Langford, Cestrian Software



Sun, 05 Sep 1999 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Bitwise operations

2. bitwise operations (try #2)

3. Question: Bitwise operations in Oberon

4. Bitwise operations on X's and Z's

5. Bitwise operations in Scheme

6. bitwise operation on 64 bits value, how?

7. bitwise operations in Ada95

8. Help: bitwise operations on a 56 bit word

9. Help: bitwise operations on a 56 bit word

10. Bitwise Operations

11. F77 Equivalents for Bitwise Operations?

12. : strings and bitwise operations?

 

 
Powered by phpBB® Forum Software