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

Convert given decimal number into Binary


IBM Mainframe Forums -> Java & MQSeries
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Shah

New User


Joined: 05 Sep 2006
Posts: 18

PostPosted: Sat Dec 16, 2006 7:15 pm
Reply with quote

Hi all,

How can we Convert given decimal number into Binary?

Thanks,
Shah
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: Tue Dec 26, 2006 9:57 pm
Reply with quote

Hello,

Try

05 flda pic s9(7) comp-3.
05 fldb pic s9(7) comp.

COMPUTE FLDA = (whatever * 3).
MOVE FLDA to FLDB.

At this point, flda and fldb will contain the same numeric value - flda stored in packed decimal and fldb stored in binary.
Back to top
View user's profile Send private message
Shah

New User


Joined: 05 Sep 2006
Posts: 18

PostPosted: Wed Jan 03, 2007 6:08 pm
Reply with quote

dick scherrer,

Could you please give the code in NATURAL language.

Thanks,
Shaik
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: Wed Jan 03, 2007 9:00 pm
Reply with quote

Hi Shaik,

My current "inventory" doesn't include NATURAL.

I'd suggest looking in the NATURAL referance documentation for syntax - in the section on "working data" or "defining elementary fields" or something similar.

You might also check on how numeric fields are defined in ADABAS. Your NATURAL programs can both read and write various numeric formats.

Sorry that i can't be more help.
Back to top
View user's profile Send private message
ofer71

Global Moderator


Joined: 27 Dec 2005
Posts: 2358
Location: Israel

PostPosted: Thu Jan 04, 2007 1:47 am
Reply with quote

Shah -

Here is something I wrote few minutes ago. It is not perfect, but you'll get the idea.
Code:
DEFINE DATA LOCAL                                     
1 #DECIMAL (N4)                                       
1 #BINARY  (N23)                                       
1 REDEFINE #BINARY                                     
  2 #BIN   (N1/23)                                     
1 #I       (I2) INIT <23>                             
1 #J       (I2) INIT <0>                               
1 #RES     (N4)                                       
END-DEFINE                                             
*                                                     
COMPUTE #DECIMAL = 5555                               
*                                                     
REPEAT UNTIL #DECIMAL LE 1                             
  DIVIDE 2 INTO #DECIMAL GIVING #RES REMAINDER #BIN(#I)
  COMPUTE #DECIMAL = #DECIMAL / 2                     
  COMPUTE #I = #I - 1                                 
END-REPEAT                                             
*                                                     
COMPUTE #BIN(#I) = #DECIMAL                           
*                                                     
DISPLAY #BINARY                                       
END                                                   


O.
Back to top
View user's profile Send private message
Shah

New User


Joined: 05 Sep 2006
Posts: 18

PostPosted: Thu Jan 04, 2007 2:29 pm
Reply with quote

Ofer71,

Thanks for giving code. I will try that and let you know.

Thank u very much,
Shah
Back to top
View user's profile Send private message
Shah

New User


Joined: 05 Sep 2006
Posts: 18

PostPosted: Thu Jan 04, 2007 2:57 pm
Reply with quote

Ofer71,

Just now i tried with that code, That's great, its working exactly. But i need some clarifications (because iam just stepping into NATURAL recently).

1. Why you consider #BINARY as (N23) , is there any reason.
2. Redefined #BINARY as #BIN with (N1/23)? What it its meaning.

Please clarify if you have time.

Thanks in advance,
Shah
Back to top
View user's profile Send private message
ofer71

Global Moderator


Joined: 27 Dec 2005
Posts: 2358
Location: Israel

PostPosted: Thu Jan 04, 2007 4:06 pm
Reply with quote

Shah -

The "23" is just a number. You may change it to whatever suitable for you. Same for the #BIN array. It is used to place the bits under #BINARY.

O.
Back to top
View user's profile Send private message
Shah

New User


Joined: 05 Sep 2006
Posts: 18

PostPosted: Thu Jan 04, 2007 4:50 pm
Reply with quote

Thanks Ofer71,

Regards,
Shaik
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 -> Java & MQSeries

 


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