Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

negative value in easytriev

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> CA Products
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    Post subject: negative value in easytriev
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

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Thu Sep 16, 2010 7:08 pm    Post subject:
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: 8002
Location: Bellevue, IA

PostPosted: Thu Sep 16, 2010 7:18 pm    Post subject:
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    Post subject:
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

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Thu Sep 16, 2010 7:59 pm    Post subject:
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    Post subject:
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

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Thu Sep 16, 2010 8:24 pm    Post subject:
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    Post subject:
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    Post subject:
Reply with quote

just in case someone else is interested:
http://en.wikipedia.org/wiki/Two%27s_complement
thanks.
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Thu Sep 16, 2010 8:55 pm    Post subject:
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    IBMMAINFRAMES.com Support Forums -> CA Products All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Negative value used in IFTHEN jacobdng DFSORT/ICETOOL 3 Tue Aug 04, 2015 2:12 pm
No new posts Does FUNCTION NUMVAL work for alphanu... Venkata Ramayya COBOL Programming 8 Fri Mar 20, 2015 10:43 pm
No new posts Conversion of negative amount (comp3)... dharmaraok COBOL Programming 9 Mon Feb 24, 2014 5:27 pm
No new posts Extract records from a file based on ... suraaj DFSORT/ICETOOL 6 Wed Jan 29, 2014 1:14 am
No new posts Data representation with negative values Raghu navaikulam COBOL Programming 4 Tue Jan 14, 2014 9:36 am


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us