View previous topic :: View next topic
|
Author |
Message |
Velkumar
New User
Joined: 23 Apr 2007 Posts: 18 Location: India
|
|
|
|
I have a requirement where I need to convert a decimal number to Binary number. Then I will have to check the individual bits of the binary and findout if any bit is 'ON' to process further.
Can anyone help me in converting a decimal number to Binary format. Can I store the converted bits into Alphanumeric variable? |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
I suggest that you look at this website which provides examples of this kind of stuff. That should give you a starting point. |
|
Back to top |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
05 decimal-number pic s9(4).
05 binary-number pic s9(4) comp.
05 filler redefines binary-number.
10 filler pic x.
10 alphanumeric pic x.
move decimal-number to binary-number.
While the following will only get you the first bit, it should give you an idea:
evaluate decimal-number
when > 127 X'1nnnnnnn'
when > 063 X'n1nnnnnn'
when > 031 X'nn1nnnnn'
when > 015 X'nnn1nnnn'
when > 007 X'nnnn1nnn'
when > 003 X'nnnnn1nn'
when > 001 X'nnnnnn1n'
when > 000 X'nnnnnnn1'
end-evaluate |
|
Back to top |
|
|
star_dhruv2000
New User
Joined: 03 Nov 2006 Posts: 87 Location: Plymouth, MN USA
|
|
|
|
It will be good if u Redefine a COMP variable onto your normal variable.
E.G.
Code: |
01A PIC 9(2).
01B PIC S9(4) COMP. |
Now you can use B as individual bits |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Quote: |
It will be good if u Redefine a COMP variable onto your normal variable.
E.G.
Code: |
01A PIC 9(2).
01B PIC S9(4) COMP. |
Now you can use B as individual bits
|
Please explain how you might use the individual bits of B. . . .
If you used a redefine (mentioned, but not shown in the code) and the value in A was 32 (x'F3F2'), the decimal "value" of B would be 62450. I'm not sure how either makes the individual bits "visable". I believe the bit settings for the 2 bytes would be "1111 0011 1111 0010". |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
You could also check out the Language Environment Service: CEESITST, which is found in SA22-7562-03 z/OS V1R4.0 Language Environment Programming Reference
Code: |
2.3.4 CEESITST--Bit test CEESITST selectively tests a bit in its parm1 input to determine if the bit is on.
___ Syntax _____________________________________________________________
| |
| >>__CEESITST__(__parm1__,__parm2__,__fc__,__result__)_______________>< |
| |
|________________________________________________________________________|
parm1 (input)
The first input to the Bit Test routine. The input can be any 32-bit integer.
parm2 (input)
The second input to the Bit Test routine. The input is a 32-bit integer in the range 0 <= parm2 <= 31.
fc (output)
A 12-byte feedback code, optional in some languages, that indicates the result of this service. The following symbolic conditions can result from this service:
result (output)
The result of the Bit Test routine. The output is a 32-bit integer with value:
1, if bit number parm2 in parm1 is 1
0, if bit number parm2 in parm1 is 0
Bits are counted from the righ
|
|
|
Back to top |
|
|
|