View previous topic :: View next topic |
Author |
Message |
srikanth.bh Beginner
Joined: 23 Jul 2004 Posts: 8 Topics: 4
|
Posted: Wed Aug 11, 2004 2:37 pm Post subject: moving 9(10) to s9(9) comp |
|
|
Hi all,
I am trying to move a variable of pic 9(10) to s9(9) comp. getting some junk values in output however i try. please suggest how to accomplish this.
thanks,
kanth |
|
Back to top |
|
|
kolusu Site Admin
Joined: 26 Nov 2002 Posts: 12375 Topics: 75 Location: San Jose
|
Posted: Wed Aug 11, 2004 3:16 pm Post subject: |
|
|
Srikanth,
You need to tell us what you meant by junk value. The following program shows the move of 9(10) to s9(09) comp.
Code: |
CBL TRUNC(BIN)
IDENTIFICATION DIVISION.
PROGRAM-ID. SAMPLE
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 W-NUM PIC 9(10).
01 W-COMP PIC S9(9) COMP.
PROCEDURE DIVISION.
MOVE 1234567890 TO W-NUM
MOVE W-NUM TO W-COMP
DISPLAY 'NUM VALUE IS : ' W-NUM
DISPLAY 'COMP VALUE IS : ' W-COMP
GOBACK.
|
The output from this job is :
Code: |
NUM VALUE IS : 1234567890
COMP VALUE IS : 1234567890
|
Hope this helps...
Cheers
Kolusu _________________ Kolusu
www.linkedin.com/in/kolusu |
|
Back to top |
|
|
srikanth.bh Beginner
Joined: 23 Jul 2004 Posts: 8 Topics: 4
|
Posted: Thu Aug 12, 2004 12:24 am Post subject: |
|
|
Kolusu, thanks for the response. Initially when i tried this direct move i got strange output.
01 A PIC 9(10) VALUE 3420009659
01 B PIC S9(9) COMP.
MOVE A TO B.
OUTPUT:
A = 3420009659
B = -874957637
i'm failing to understand how B had such a value. |
|
Back to top |
|
|
srikanth.bh Beginner
Joined: 23 Jul 2004 Posts: 8 Topics: 4
|
Posted: Thu Aug 12, 2004 3:25 am Post subject: |
|
|
Actually, the MOVE statement in inside a loop. so i think each time the move is made the values are getting computed with the old value in comp. when i tried initializing the comp filed before each move i could get the result correctly.
sorry for taking your time, thanks. |
|
Back to top |
|
|
Mike Chantrey Intermediate
Joined: 10 Sep 2003 Posts: 234 Topics: 1 Location: Wansford
|
Posted: Thu Aug 12, 2004 10:25 am Post subject: |
|
|
The maximum positive value you can store in an S9(9) COMP field is 2^31 which is 2147483648, i.e. the value you are trying to move is too big. So it wraps around into the negative range. Negative values are stored in 'twos complement' fashion so if you convert the value in B to its unsigned equivalent you will see that the unsigned value is actually correct, i.e. 2^32 - 874957637 = 3420009659
As far as I can see this explains you result rather than your loops... |
|
Back to top |
|
|
srikanth.bh Beginner
Joined: 23 Jul 2004 Posts: 8 Topics: 4
|
Posted: Thu Aug 12, 2004 12:44 pm Post subject: |
|
|
that makes more sense mike. thanks for clarifying. |
|
Back to top |
|
|
|
|