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
 

 

Need to convert Binary value to Decimal

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
Amb

New User


Joined: 12 Mar 2010
Posts: 64
Location: India

PostPosted: Wed May 12, 2010 4:34 pm    Post subject: Need to convert Binary value to Decimal
Reply with quote

Hi Guys,

I have a variable which contains a binary value. I need to convert it to a decimal value.
Please let me know if we have an intrinsic function in COBOL to do this.
If not can you please give me a small logic to do the same.
Back to top
View user's profile Send private message

Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2502
Location: Atlanta, Georgia, USA

PostPosted: Wed May 12, 2010 4:50 pm    Post subject: Reply to: Need to convert Binary value to Decimal
Reply with quote

Code:

03  WS-BINARY PIC S9(09) BINARY VALUE 1234.
03  WS-PACKED PIC S9(15) PACKED-DECIMAL.
*
MOVE WS-BINARY TO WS-PACKED.

Please spend more time reviewing basic stuff. This aggravates many members....

Bill
Back to top
View user's profile Send private message
Kjeld

Active User


Joined: 15 Dec 2009
Posts: 365
Location: Denmark

PostPosted: Thu May 13, 2010 2:37 am    Post subject:
Reply with quote

And no... MOVE is not an intrinsic function in Cobol icon_exclaim.gif icon_rolleyes.gif

Thanks Bill, for bothering.
Back to top
View user's profile Send private message
Anuj Dhawan

Senior Member


Joined: 22 Apr 2006
Posts: 6258
Location: Mumbai, India

PostPosted: Thu May 13, 2010 4:31 pm    Post subject:
Reply with quote

First, are you wanting to display the decimal equivalent of some Binary number or just the Decimal value of digits in Binary? Example: the binary for '1' is 0001, '2' is 0010, etc. This is VERY different from the Binary for 12345, for example?

Either way, you convert from a number base by dividing by the number base, using the remainder as the digit position, from right to left in the result and looping until the quotient is zero. You do the inverse to go the other way.

Another way would be to use a table with the decimal digits encoded as binary literals, but this only works on a digit basis and not a logical number base.

And why COBOL functions looks like a choice to you?
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 How to convert the VBM file to VB or... Sulabh Agrawal JCL & VSAM 4 Fri Nov 18, 2016 1:04 pm
No new posts Convert +9999999999999.99 to S9(12)V9(3) vnktrrd DFSORT/ICETOOL 8 Thu Nov 17, 2016 8:15 pm
This topic is locked: you cannot edit posts or make replies. Db2 SQL query to convert rows into co... subratarec DB2 5 Thu Nov 17, 2016 4:51 pm
No new posts convert PD to ZD ram_vizag DFSORT/ICETOOL 5 Sat Nov 05, 2016 3:06 am
No new posts Comparing Decimal and CHAR columns rakesh17684 DB2 7 Thu Oct 20, 2016 2:33 am


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