Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Convert a decimal number to Binary number

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: Convert a decimal number to Binary number
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: 6967
Location: porcelain throne

PostPosted: Wed Aug 22, 2007 3:03 pm    Post subject:
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: 3158
Location: Tucson AZ

PostPosted: Wed Aug 22, 2007 3:14 pm    Post subject:
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    Post subject:
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

Site Director


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

PostPosted: Fri Aug 24, 2007 9:14 pm    Post subject:
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: 6967
Location: porcelain throne

PostPosted: Sat Aug 25, 2007 12:10 am    Post subject:
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts SMTP the current generation number of... Jyothi Kulunde JCL & VSAM 4 Thu May 04, 2017 4:08 pm
No new posts Edit large number of datasets (QSAM) zh_lad TSO/ISPF 3 Tue Apr 04, 2017 6:08 pm
No new posts how to mask the phone number kumarinfy DB2 4 Mon Apr 03, 2017 5:23 pm
No new posts Check Binary Values for symbols gandikk CA Products 3 Tue Mar 21, 2017 5:11 am
No new posts what is meaning of the number in dcl Martylin PL/I & Assembler 2 Thu Mar 09, 2017 7:18 am


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us