View previous topic :: View next topic
|
Author |
Message |
dharmaraok
New User
Joined: 10 Mar 2011 Posts: 45 Location: india
|
|
|
|
I have an amount field having below value.
00211
0011D
I need to convert this amount field into 2'c ompliment in the below way.
FFF2
FFFB
after converting into 2's compliment . how to convert into comp-3 format again.
Could you please let me know how can we achieve through COBOL pgm. |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8697 Location: Dubuque, Iowa, USA
|
|
|
|
What you want cannot be done -- PERIOD. COMP-3 data is numbers (as in digits zero through nine) and a sign nubble exclusively. You may convert your value to 2's complement, or you may have your value in COMP-3 -- you CANNOT have both. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
How will these flip-flopped values intended to be used?
If you explain what the usage will be someone may have an alternate suggestion.
You could define another field and keep both? |
|
Back to top |
|
|
Rohit Umarjikar
Global Moderator
Joined: 21 Sep 2010 Posts: 3053 Location: NYC,USA
|
|
|
|
You might wants to try converting 2's to Disply first and then Decimal. |
|
Back to top |
|
|
steve-myers
Active Member
Joined: 30 Nov 2013 Posts: 917 Location: The Universe
|
|
|
|
When Cobol converts data in packed decimal to "2s complement," which most of us call binary, it uses the hardware CVB (Convert to Binary) instruction, either inline or in a subroutine. CVB automatically creates the proper 2s complement value.
I wrote up the following sample Assembler program to show the steps that Cobol performs.
Code: |
CVBNEG CSECT
USING *,12
SAVE (14,12),,*
LR 12,15
ZAP DWORK,SOURCE
CVB 0,DWORK
ST 0,RESULT
UNPK MSG1VAL(L'MSG1VAL+1),SOURCE(L'SOURCE+1)
NC MSG1VAL,=16X'0F'
TR MSG1VAL,HEXTAB
UNPK MSG2VAL(9),DWORK(5)
UNPK MSG2VAL+8(L'MSG2VAL-8+1),DWORK+4(L'DWORK-4+1)
NC MSG2VAL,=16X'0F'
TR MSG2VAL,HEXTAB
UNPK MSG3VAL(L'MSG3VAL+1),RESULT(L'RESULT+1)
NC MSG3VAL,=16X'0F'
TR MSG3VAL,HEXTAB
LA 0,L'MSG1
LA 1,MSG1
TPUT (1),(0),R
LA 0,L'MSG2
LA 1,MSG2
TPUT (1),(0),R
LA 0,L'MSG3
LA 1,MSG3
TPUT (1),(0),R
RETURN (14,12),T,RC=0
DWORK DC D'0'
HEXTAB DC C'0123456789ABCDEF'
RESULT DC F'0'
SOURCE DC X'000021111D'
MSG1 DC 0C'SOURCE = 000021111D'
DC C'SOURCE = '
MSG1VAL DC CL(L'SOURCE*2)' ',C' '
MSG2 DC 0C'DWORK = 0123456789ABCDEF'
DC C'DWORK = '
MSG2VAL DC CL(L'DWORK*2)' ',C' '
MSG3 DC 0C'RESULT = 01234567'
DC C'RESULT = '
MSG3VAL DC CL(L'RESULT*2)' ',C' '
END CVBNEG |
The CVB instruction uses an 8 byte packed decimal data area, so the ZAP (Zero and Add Decimal) instruction expands the source to 8 bytes. The output from CVB is in a register, so the program stores the 32-bit register value. The remainder of the program translates the data areas to hexadecimal data for display purposes. TPUT is a macro to display a message at a TSO user's workstation, and is much easier than more traditional mechanisms for a simple program like this.
The output as displayed on my TSO workstation is
Code: |
SOURCE = 000021111D
DWORK = 000000000021111D
RESULT = FFFFAD89 |
|
|
Back to top |
|
|
dharmaraok
New User
Joined: 10 Mar 2011 Posts: 45 Location: india
|
|
|
|
Robert,
I need only one conversion from - neg comp-3 to 2's compliment.
Could you please let me know the logic in cobol.
I have an amount field having below value.
00211
0011D
I need to convert this amount field into 2'c ompliment in the below way.
FFF2
FFFB
Thanks,
Dharma Rao |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
read the COBOL manual about the definition of a BINARY number
and after that a plain good old assignment statement will do!
in every computer/hardware binary negative numbers are stored in the two complement representation
but still the question does not make any sense |
|
Back to top |
|
|
dharmaraok
New User
Joined: 10 Mar 2011 Posts: 45 Location: india
|
|
|
|
enrico,
Could you please let me know the cobol logic ; how can it be done |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
we are going into a loop here ...
start by reading the IBM pronicple of operations ably the number reprentation in IBM z architecture machines ,
here anyway a short resume of it
using the number 100 as an example
Code: |
zoned positive
x'F1F0C0'
zoned negative
x'F1F0D0'
packed positive
x'100c'
packed negative
x'100d'
binary positive
x'00000064'
binary negative ( 2's complement notation )
x'FFFFFF9C'
|
the transformation from one format to the other is done
using the proper COBOL declarations
and the move instruction
anyway Your math is just wrong
the binary representation of -21111 is x'FFFFAD89'
what you posted is the representation of a -213
so... reset Your neurons and start over from scratch
You can test everything with a simple rexx snippet ...
Code: |
say c2x(D2C(-21111, 4))
say c2d("FFFFFF2b"x,4)
say c2x(D2C(100, 4))
say c2x(D2C(-100, 4))
|
|
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Unless i misunderstand, can you not simply MOVE the value frm one field type to the other?
Then wriote bpth fields into a file and view the file in hex.
As i mentioned before, if you explain how this will be used, we can provide more useful replies . . . |
|
Back to top |
|
|
|