View previous topic :: View next topic
|
Author |
Message |
jctgf Currently Banned Active User
Joined: 04 Nov 2006 Posts: 109
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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 |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
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 |
|
|
jctgf Currently Banned Active User
Joined: 04 Nov 2006 Posts: 109
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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 |
|
|
jctgf Currently Banned Active User
Joined: 04 Nov 2006 Posts: 109
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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 |
|
|
jctgf Currently Banned Active User
Joined: 04 Nov 2006 Posts: 109
|
|
|
|
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 |
|
|
jctgf Currently Banned Active User
Joined: 04 Nov 2006 Posts: 109
|
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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 |
|
|
|