View previous topic :: View next topic |
Author |
Message |
semigeezer Supermod
Joined: 03 Jan 2003 Posts: 1014 Topics: 13 Location: Atlantis
|
Posted: Wed Nov 16, 2005 5:07 pm Post subject: Working with bits in COBOL |
|
|
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 X 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'
|
|
Back to top |
|
|
kolusu Site Admin
Joined: 26 Nov 2002 Posts: 12376 Topics: 75 Location: San Jose
|
|
Back to top |
|
|
semigeezer Supermod
Joined: 03 Jan 2003 Posts: 1014 Topics: 13 Location: Atlantis
|
Posted: Wed Nov 16, 2005 8:35 pm Post subject: |
|
|
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. |
|
Back to top |
|
|
MikeBaker Beginner
Joined: 04 May 2004 Posts: 96 Topics: 9
|
Posted: Thu Nov 17, 2005 1:50 am Post subject: |
|
|
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... |
|
Back to top |
|
|
|
|