× 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 was just going to do it off the top of my head, but here's a working program. It takes a TWO character field and converts the SECOND byte to binary and displays it. I only did that because %BINARY won't work on a one-character field. Call like this:

CALL BINARY X'002B'

The result will be 00101011

You'll have to apply a bit of your own logic to either divide by the appropriate first number (a power of two) to isolate your bit, or else use this sort of logic to convert the whole thing and then extract the bits from the CHAR field as needed.

HTH!

Joe

P.S. Yes, this could have been done much more nicely with a loop. I leave that exercise to the reader. :)


BINARY: PGM (&CHAR)
DCL &CHAR *CHAR 2
DCL &BINARY *DEC (5 0)
DCL &BINARY2 *DEC (5 0)
DCL &BIT *DEC (1 0)
DCL &BITS *CHAR 8

CHGVAR &BINARY %BINARY(&CHAR)

CHGVAR &BINARY2 (&BINARY / 2) /* Divide by two */
CHGVAR &BIT (&BINARY - (&BINARY2 * 2)) /* Get remainder */
CHGVAR %SST(&BITS 8 1) &BIT /* Stuff into char field */

CHGVAR &BINARY (&BINARY / 2) /* SHIFT RIGHT 1 BIT */
CHGVAR &BINARY2 (&BINARY / 2)
CHGVAR &BIT (&BINARY - (&BINARY2 * 2))
CHGVAR %SST(&BITS 7 1) &BIT

CHGVAR &BINARY (&BINARY / 2) /* SHIFT RIGHT 1 BIT */
CHGVAR &BINARY2 (&BINARY / 2)
CHGVAR &BIT (&BINARY - (&BINARY2 * 2))
CHGVAR %SST(&BITS 6 1) &BIT

CHGVAR &BINARY (&BINARY / 2) /* SHIFT RIGHT 1 BIT */
CHGVAR &BINARY2 (&BINARY / 2)
CHGVAR &BIT (&BINARY - (&BINARY2 * 2))
CHGVAR %SST(&BITS 5 1) &BIT

CHGVAR &BINARY (&BINARY / 2) /* SHIFT RIGHT 1 BIT */
CHGVAR &BINARY2 (&BINARY / 2)
CHGVAR &BIT (&BINARY - (&BINARY2 * 2))
CHGVAR %SST(&BITS 4 1) &BIT

CHGVAR &BINARY (&BINARY / 2) /* SHIFT RIGHT 1 BIT */
CHGVAR &BINARY2 (&BINARY / 2)
CHGVAR &BIT (&BINARY - (&BINARY2 * 2))
CHGVAR %SST(&BITS 3 1) &BIT

CHGVAR &BINARY (&BINARY / 2) /* SHIFT RIGHT 1 BIT */
CHGVAR &BINARY2 (&BINARY / 2)
CHGVAR &BIT (&BINARY - (&BINARY2 * 2))
CHGVAR %SST(&BITS 2 1) &BIT

CHGVAR &BINARY (&BINARY / 2) /* SHIFT RIGHT 1 BIT */
CHGVAR &BINARY2 (&BINARY / 2)
CHGVAR &BIT (&BINARY - (&BINARY2 * 2))
CHGVAR %SST(&BITS 1 1) &BIT

SNDPGMMSG MSG('RESULT: ' *CAT &BITS) TOPGMQ(*EXT)
ENDPGM

Joe: Care to share an example?

The RTVMBRD command gets me where I initially where I wanted to go
(thanks Gary and Chuck) but now I am intrigued by the other fields in
the API such as Logical vs. physical, etc.

Why I did not think of the RTVMBRD command is beyond me, I got so tied
up in wanting to use the API I did not think of it. I also did not
think to use QADBXREF (thanks Bill)

Thanks.

Jim Oberholtzer
Chief Technical Architect
Agile Technology Architects


On 12/6/2011 3:34 PM, Joe Pluta wrote:
Use %BIN to convert that byte to a numeric value. Then use
multiplication, division and subtraction to isolate the bit.

Joe

Folks:

I am working on a project where I have to determine if a file is a
source file or physical file. The problem is it will be too slow to
call DSPFD to an outfile and read it for each of the files that will be
looked at. So I was trying to use the API QDBRTVFD which is perfect for
the problem, except: The data structure IBM used for the attributes is a
16_BIT_ field. (Maybe Bruce can explain the logic behind that choice)



Constraints: Must use CL and must work at V5R4.

Any ideas how to get after that fifth bit?




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.