Working with bits in COBOL
Select messages from
# through # FAQ
[/[Print]\]

MVSFORUMS.com -> Application Programming

#1: Working with bits in COBOL Author: semigeezerLocation: Atlantis PostPosted: Wed Nov 16, 2005 5:07 pm
    —
I'm certainly no COBOL expert and I realize that COBOL is not intended to be used for system programming types of tasks, but is there a way to address individual bits within a byte? For simply testing a bit, I've resorted to this horrible method, which works, but there must be a better COBOL-only solution... is there? And how would one set a bit on or off? I didn't find any binary operators.

              01  oucb.
                  05 oucboucb        pic x(4).
                  05 filler          pic x(33).
                  05 oucbomvs        pic x.
              01 Filler.
                  05 Bin-Merge.
                    10 Bin-Hi        pic value low-Value.
                    10 Bin-Low       pic X.
                  05 Binnum redefines bin-Merge pic s99 binary.
              01  X10-Data.
                02  pic x(16) value X'000000000000000000000000000000'.
                02  pic x(16) value X'101010101010101010101010101010'.
                02  pic x(16) value X'000000000000000000000000000000'.
                02  pic x(16) value X'101010101010101010101010101010'.
                02  pic x(16) value X'000000000000000000000000000000'.
                02  pic x(16) value X'101010101010101010101010101010'.
                02  pic x(16) value X'000000000000000000000000000000'.
                02  pic x(16) value X'101010101010101010101010101010'.
                02  pic x(16) value X'000000000000000000000000000000'.
                02  pic x(16) value X'101010101010101010101010101010'.
                02  pic x(16) value X'000000000000000000000000000000'.
                02  pic x(16) value X'101010101010101010101010101010'.
                02  pic x(16) value X'101010101010101010101010101010'.
                02  pic x(16) value X'000000000000000000000000000000'.
                02  pic x(16) value X'101010101010101010101010101010'.
                02  pic x(16) value X'000000000000000000000000000000'.
              01 X10 redefines x10-Data pic x(256).
       
               move oucbomvs to bin-low
               if x10((binnum + 1):1) NOT = x'10'
       

#2:  Author: kolusuLocation: San Jose PostPosted: Wed Nov 16, 2005 5:51 pm
    —
semigeezer,

You can actually usel language environment calls to perform bit checking and manipulation

Check this link

http://publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/BOOKS/CEEA3130/4.0?DT=20020625092930

Hope this helps...

Cheers

Kolusu

#3:  Author: semigeezerLocation: Atlantis PostPosted: Wed Nov 16, 2005 8:35 pm
    —
Great! Thanks. Seems a bit odd to me (no pun intended) that this isn't a built in part of COBOL, particularly since COBOL was developled when memory was so tight that every bit should have counted, but if this is what it takes, that'll do. Thanks again.

#4:  Author: MikeBaker PostPosted: Thu Nov 17, 2005 1:50 am
    —
Also have a look at http://www.simotime.com/cblbit01.htm

Years ago, I also came across another COBOL program which manipulated bits, and it sure seemed alot smaller than the Simotime one. Cannot remember the code though...



MVSFORUMS.com -> Application Programming


output generated using printer-friendly topic mod. All times are GMT - 5 Hours

Page 1 of 1

Powered by phpBB © 2001, 2005 phpBB Group