IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Convert a decimal number to Binary number


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Velkumar

New User


Joined: 23 Apr 2007
Posts: 18
Location: India

PostPosted: Wed Aug 22, 2007 2:33 pm
Reply with quote

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
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Wed Aug 22, 2007 3:03 pm
Reply with quote

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
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Wed Aug 22, 2007 3:14 pm
Reply with quote

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
View user's profile Send private message
star_dhruv2000

New User


Joined: 03 Nov 2006
Posts: 87
Location: Plymouth, MN USA

PostPosted: Fri Aug 24, 2007 4:42 pm
Reply with 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
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Fri Aug 24, 2007 9:14 pm
Reply with quote

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
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Sat Aug 25, 2007 12:10 am
Reply with quote

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
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts Pulling a fixed number of records fro... DB2 2
No new posts Substring number between 2 characters... DFSORT/ICETOOL 2
No new posts Generate random number from range of ... COBOL Programming 3
No new posts Need to convert date format DFSORT/ICETOOL 20
Search our Forums:

Back to Top