× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



I liked this version:

Out of every 10 people, one understands binary, the other doesn't.

Dave B

>>> CWilt@xxxxxxxxxxxx 08/12/2004 3:22:09 PM >>>
A computer engineering professor I once had wrote the following on the
overhead one day:

There are 10 types of people in the world...

* Those that know binary
* Those that don't


Charles


> -----Original Message-----
> From: Scott Klement [mailto:rpg400-l@xxxxxxxxxxxxxxxx] 
> Sent: Thursday, August 12, 2004 4:08 PM
> To: RPG programming on the AS400 / iSeries
> Subject: Re: help in getting 7th bit
> 
> 
> 
> 
> When you say "7th bit" do you mean the 7th bit from the left 
> hand side of
> the byte or the 7th from the right-hand side? Do you start 
> numbering your
> bits with 0?  or do you start numbering them from 1?
> 
> In other words, if you have a byte with a value of "10000000," which
> bit is set?  Is it number 0, 1, 7 or 8?
> 
> Once you've decided which bit you want to check, create a mask (like
> "01000000" , where each bit you want ot check is 1, and each 
> bit you don't
> care about is 0) convert the binary number to hex, and use 
> the %bitand()
> BIF to check it.
> 
> For example:
> 
>       /free
> 
>            // The binary number 01000000 is hex x'40'
> 
>            if (%bitand(YSTAT1: x'40') <> x'00');
>                dsply ('7th bit from the right is set');
>            endif;
> 
>            // The binary number 00000010 is hex x'02'
> 
>            if (%bitand(YSTAT1: x'02') <> x'00');
>                dsply ('7th bit from the left is set');
>            endif;
> 
>       /end-free
> 
> 
> If you're running a release older than V5R2, you can 
> accomplish the same
> thing with the TESTB op-code:
> 
>       *
>       *  The binary number 01000000 is hex x'40'
>       *
>       * 
> N01Factor1+++++++Opcode&ExtFactor2+++++++Result++++++++Len++D+HiLoEq
>      c                   testb     x'40'         YSTAT1       
>             99
>      c                   if        *in99 = *on
>      c                   eval      msg = '7th bit from the 
> right is on'
>      c     msg           dsply
>      c                   endif
> 
>       *
>       *  The binary number 01000000 is hex x'02'
>       *
>       * 
> N01Factor1+++++++Opcode&ExtFactor2+++++++Result++++++++Len++D+HiLoEq
>      c                   testb     x'02'         YSTAT1       
>             99
>      c                   if        *in99 = *on
>      c                   eval      msg = '7th bit from the left is
on'
>      c     msg           dsply
>      c                   endif
> 
> Personally, I like to make it a more obvious WHY I'm checking 
> this bit.
> For that type of thing, I define a named constant that 
> corresponds to the
> bit I'm checking.  For example, if bit 7 is determined to be 
> 01000000 and
> I'm checking it because it's turned on when an account has 
> been paid in
> full, I'd define a constant like this:
> 
>      D PaidInFull      c                   x'40'
> 
> And then I'd do my test like this:
> 
>            if (%bitand(YSTAT1: PaidInFull) <> x'00');
> 
> or in older RPG programs:
> 
>       * 
> N01Factor1+++++++Opcode&ExtFactor2+++++++Result++++++++Len++D+HiLoEq
>      c                   testb     PaidInFull    YSTAT1       
>             99
> 
> I usually bit all of these "bit flags" in a /copy member so that I
can
> reuse them in every program that might need to check the 
> status of a bit
> without needing to redefine them everywhere.
> 
> 
> --
> This is the RPG programming on the AS400 / iSeries (RPG400-L) 
> mailing list
> To post a message email: RPG400-L@xxxxxxxxxxxx 
> To subscribe, unsubscribe, or change list options,
> visit: http://lists.midrange.com/mailman/listinfo/rpg400-l 
> or email: RPG400-L-request@xxxxxxxxxxxx 
> Before posting, please take a moment to review the archives
> at http://archive.midrange.com/rpg400-l.
> 
--
This is the RPG programming on the AS400 / iSeries (RPG400-L) mailing
list
To post a message email: RPG400-L@xxxxxxxxxxxx 
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/rpg400-l 
or email: RPG400-L-request@xxxxxxxxxxxx 
Before posting, please take a moment to review the archives
at http://archive.midrange.com/rpg400-l.




As an Amazon Associate we earn from qualifying purchases.

This thread ...


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.