View previous topic :: View next topic
|
Author |
Message |
Shah
New User
Joined: 05 Sep 2006 Posts: 18
|
|
|
|
Hi all,
How can we Convert given decimal number into Binary?
Thanks,
Shah |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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 |
|
|
Shah
New User
Joined: 05 Sep 2006 Posts: 18
|
|
|
|
dick scherrer,
Could you please give the code in NATURAL language.
Thanks,
Shaik |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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 |
|
|
ofer71
Global Moderator
Joined: 27 Dec 2005 Posts: 2358 Location: Israel
|
|
|
|
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 |
|
|
Shah
New User
Joined: 05 Sep 2006 Posts: 18
|
|
|
|
Ofer71,
Thanks for giving code. I will try that and let you know.
Thank u very much,
Shah |
|
Back to top |
|
|
Shah
New User
Joined: 05 Sep 2006 Posts: 18
|
|
|
|
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 |
|
|
ofer71
Global Moderator
Joined: 27 Dec 2005 Posts: 2358 Location: Israel
|
|
|
|
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 |
|
|
Shah
New User
Joined: 05 Sep 2006 Posts: 18
|
|
|
|
Thanks Ofer71,
Regards,
Shaik |
|
Back to top |
|
|
|