On 31/05/2005, at 10:12 PM, Fisher, Don wrote:

I'm actually just trying to determine the status of a specific bit. As I
understand the a.p.i. documentation, this one character field contains bit
data that may look like '01110000' or '01001000' or something else depending
on what the a.p.i. detects. The third bit (bit number 2), may be on or off
and I need to determine which.

Then you simply define a mask which has the third bit set on and use %BITAND to perform a logical AND operation between the original value and the mask and then compare the result of the AND operation to the mask.


In IBM systems (not PCs) bits are numbered from left to right starting with bit 0 (being the most significant bit) so an 8-bit value with only bit 2 set on is 00100000 which is x'20' in hexadecimal.

Thus:
                IF              ( %BITAND(value : x'20') = x'20' )

although using named constants for the mask values would be better.

If you need this explained in detail then you should convert the input value to binary and perform boolean arithmetic with the mask. Thus:

Original value: 01110000 x'70' determined by adding the value of the set bit positions
AND Mask: 00100000 x'20'
--------
Result: 00100000 x'20' See how the result of an AND is the same as the mask if the
mask bits are on in the original value? A bit is set on in
the result if that bit is on in both input values (i.e.,
the bit is ON in the original value AND in the mask).


Here's the same operation with a different input value.
Original value: 01011111 x'5f'
AND Mask: 00100000 x'20'
--------
Result: 00000000 x'00' See how the result of an AND is 0 when the mask bits are
not set in the original value?


The same principle holds for multi-bit masks such as x'55'.

Regards,
Simon Coulter.
--------------------------------------------------------------------
   FlyByNight Software         AS/400 Technical Specialists

   http://www.flybynight.com.au/
   Phone: +61 3 9419 0175   Mobile: +61 0411 091 400        /"\
   Fax:   +61 3 9419 0175                                   \ /
                                                             X
                 ASCII Ribbon campaign against HTML E-Mail  / \
--------------------------------------------------------------------



As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.