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

negative value in easytriev


IBM Mainframe Forums -> CA Products
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
jctgf
Currently Banned

Active User


Joined: 04 Nov 2006
Posts: 109

PostPosted: Thu Sep 16, 2010 7:03 pm
Reply with quote

hi there,

Code:


   Display  Filter  View  Print  Options  Help                                 
 -------------------------------------------------------------------------------
 DESA OUTPUT DISPLAY J948EMVT JOB27332  DSID   102 LINE 1       COLUMNS 02- 81 
 COMMAND INPUT ===>                                            SCROLL ===> CSR 
16/09/10 10.28.48                             CA-EASYTRIEVE PLUS-6.4 0311       
                                                     
PROGRAMS AND ALL SUPPORTING MATERIALS COPYRIGHT (C) 1982, 1996 BY COMPUTER ASSOC
                                                                               
     1 FILE ARQA                                                               
     2 A  W  2 B 0                                                             
                                                                               
     3 JOB INPUT NULL                                                           
     4 A = -1                                                                   
     5 DISPLAY 'AAA='    A                                                     
     6 DISPLAY HEX A                                                           
     7 STOP EXECUTE                                                             
OPTIONS FOR THIS RUN - ABEXIT SNAP  DEBUG (CLIST STATE FLDCHK NOXREF)  LIST (PAR
SORT (DEVICE SYSDA  ALTSEQ NO  MSG DEFAULT  MEMORY  2048  WORK   3)  VFM (   64)
16/09/10 10.28.48                             CA-EASYTRIEVE PLUS-6.4 0311       
                                                 
PROGRAMS AND ALL SUPPORTING MATERIALS COPYRIGHT (C) 1982, 1996 BY COMPUTER ASSOC
CLIST                                                                           
PROGRAM STORAGE BLOCK NUMBER   1                                               
 CA-EASYTRIEVE PLUS 6.4 0311-16/09/10-10.28-JSN00003                           
 OFFSET (HEX)     0104   0116   0168   01AE                                     
 STATEMENT NO.       4      5      6      7                                     
END OF PROGRAM                                                                 
AAA=     1-                                                                     
CHAR                                                                           
ZONE FF                                                                         
NUMR FF                                                                         
     1.                                                                         
                                                                               
******************************** BOTTOM OF DATA ********************************       

i move -1 to A, execute the "display" command and the value that appears is the correct one (-1).
when i run the "display hex" command, the content of A is x'ffff'.
why the hex value is 'ffff'?
how can it be that the hex value is 'ffff' and, at the same time, the decimal one is -1.
thanks.
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: Thu Sep 16, 2010 7:08 pm
Reply with quote

Hello,

You need to do some reading about numeric data . . . How it is stored and how it is displayed.

A -1 in a 2-byte binary is x'FFFF'.

Knowing that every value in the computer has a hex value, which hex value would you expect for a binary -1?
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Thu Sep 16, 2010 7:18 pm
Reply with quote

Quote:
how can it be that the hex value is 'ffff' and, at the same time, the decimal one is -1.
1. Because this is the way the mainframe works.

2. Because the same value can represent two different things in the computer, depending upon how it is treated. For example, hexadecimal value X'97994D' occupies three bytes. If these three bytes are displayed as characters, they will be 'pr('. If these very same bytes are displayed as a packed decimal field, the value is -97994. Which is correct? They both are -- the desired value depends entirely upon how you (or your program) is looking at those three bytes.
Back to top
View user's profile Send private message
jctgf
Currently Banned

Active User


Joined: 04 Nov 2006
Posts: 109

PostPosted: Thu Sep 16, 2010 7:43 pm
Reply with quote

hi,

if it is 'ffff', aren't all bits turned on (equal to 1)?

if so, the decimal value i'd have for 'ffff' shouldn't be
2 ** 14 +
2 ** 13 +
2 ** 12 +
2 ** 11 +
2 ** 10 +
2 ** 9 +
2 ** 8 +
2 ** 7 +
2 ** 6 +
2 ** 5 +
2 ** 4 +
2 ** 3 +
2 ** 2 +
2 ** 1 +
2 ** 0
?

Which reading would you suggest?

Thanks.
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: Thu Sep 16, 2010 7:59 pm
Reply with quote

Hello,

Quote:
If it is 'ffff', aren't all bits turned on (equal to 1)?
Yes.

Quote:
If so, the decimal value i'd have for 'ffff' shouldn't be
No, it shouldn't be.

While the internal value would be x'FFFF', how it would "display" depends on whether the value is considered signed or unsigned.

As Robert mentioned:
Quote:
Which is correct? They both are -- the desired value depends entirely upon how you (or your program) is looking at those three bytes.
Back to top
View user's profile Send private message
jctgf
Currently Banned

Active User


Joined: 04 Nov 2006
Posts: 109

PostPosted: Thu Sep 16, 2010 8:07 pm
Reply with quote

Thanks.
My doubt is precisely on how the sign works on a binary field.
I though one bit in the byte would be reserved for the sign (just as a half-byte is reserved to sign a pd field), but now I see this is not the case.
Would you recommend some reading?
Thanks.
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: Thu Sep 16, 2010 8:24 pm
Reply with quote

Hello,

Quote:
I though one bit in the byte would be reserved for the sign
Yes, it is. In a signed binary number the high-order bit is the sign - a 1 indicates a negative and a zero indicates a positive.

Quote:
Would you recommend some reading?
I don't have one off the top of my head. Time permitting, i'll look around later. . .
Back to top
View user's profile Send private message
jctgf
Currently Banned

Active User


Joined: 04 Nov 2006
Posts: 109

PostPosted: Thu Sep 16, 2010 8:28 pm
Reply with quote

Thanks.
I've just found this:
Quote:

BINARY
Specified for binary data items. Such items have a decimal equivalent consisting of the decimal digits 0 through 9, plus a sign. Negative numbers are represented as the two's complement of the positive number with the same absolute value.

I think it answers my question.
Thanks.
Back to top
View user's profile Send private message
jctgf
Currently Banned

Active User


Joined: 04 Nov 2006
Posts: 109

PostPosted: Thu Sep 16, 2010 8:40 pm
Reply with quote

just in case someone else is interested:
en.wikipedia.org/wiki/Two%27s_complement
thanks.
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: Thu Sep 16, 2010 8:55 pm
Reply with quote

Hello,

Yes, the 2's compliment is the "easy" part.

As you worked thru, the issue is the way the value is displayed and that is entirely up to the data definition in the code. By simply changing the data definition, entirely different "output" is generated. . .

Suggest you re-read Robert's earlier example. . .
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 -> CA Products

 


Similar Topics
Topic Forum Replies
No new posts Negative dependency between jobs in m... COBOL Programming 12
No new posts Negative value - packed field - Natur... Java & MQSeries 0
This topic is locked: you cannot edit posts or make replies. Missing Negative sign in COBOL COBOL Programming 6
No new posts CA7 Negative dependency JOB=/ CA Products 0
No new posts Subtract the ZD fields to provide neg... DFSORT/ICETOOL 4
Search our Forums:

Back to Top