View previous topic :: View next topic
|
Author |
Message |
koulmahesh
New User
Joined: 19 Jul 2010 Posts: 2 Location: Bangalore
|
|
|
|
Explain the output.
WORKING-STORAGE SECTION.
01 HEX-91-VALUE PIC 9(4) COMP VALUE 145.
01 HEX-91X REDEFINES HEX-91-VALUE.
15 FILLER PIC X(1).
15 HEX-91 PIC X(1).
PROCEDURE DIVISION.
DISPLAY "HEX-91-VALUE " HEX-91-VALUE
DISPLAY "HEX-91 " HEX-91
Output we got:
HEX-91-VALUE 0145
HEX-91 j
[/Search] |
|
Back to top |
|
|
Binop B
Active User
Joined: 18 Jun 2009 Posts: 407 Location: Nashville, TN
|
|
|
|
Hi Mahesh,
Why dont you start with "What u understood so far ?" |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
|
|
|
|
There is a link to manuals at the top of the page. Click on it, find the COBOL Programming Guide manual, and locate section 1.3.4.7 of this manual. You will find out how COMP variables are stored internally. Then go the COBOL Language Reference manual and read Appendix 3.1 on the EBCDIC collating sequence. This should allow you to explain the output yourself. |
|
Back to top |
|
|
CICS Guy
Senior Member
Joined: 18 Jul 2007 Posts: 2146 Location: At my coffee table
|
|
|
|
koulmahesh wrote: |
Explain the output. |
What is to explain?
Decimal 145 is hex 91 is the EBCDIC lower case 'j'......
You call yourself an SSE with "COBOL/JCL/VSAM/DB2/REXX/ASSEMBLER" skills and you don't see this?
I'd suggest you look to the Support Forum for Mainframe Beginners and Students for further help. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello and welcome to the forum,
Quote: |
Explain the output. |
First a number was displayed (145). Then a character was displayed (j). . . Keep in mind that the character might not have been a displayable value and would have appeared to be a space. . .
Possibly you are asking for something else? |
|
Back to top |
|
|
koulmahesh
New User
Joined: 19 Jul 2010 Posts: 2 Location: Bangalore
|
|
|
|
Hey .. cool ..
Thanks friends.. |
|
Back to top |
|
|
saurabh39 Warnings : 1 Active User
Joined: 11 Apr 2008 Posts: 144 Location: Jamshedpur
|
|
|
|
One question though.......how will display different value when we are referring to same memory location? |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
|
|
|
|
Tushar, the different values displayed depend upon how you look at the data. For example, if you have
Code: |
05 DATA-X PIC X(03) VALUE 'pr('.
05 DATA-N REDEFINES DATA-X
PIC S9(05) COMP-3. |
you have defined the same 3 bytes of memory in two different ways. If you display DATA-X you will see 'pr(' on your output. If you display DATA-N you will see -97994 (technically, 9799M will be the displayed value). 3 bytes with very different values depending upon how you display them. |
|
Back to top |
|
|
saurabh39 Warnings : 1 Active User
Joined: 11 Apr 2008 Posts: 144 Location: Jamshedpur
|
|
|
|
@Robert - Thanks for Quick Clarification.
But One more Clarification required- I understand the hex value for p & r is 97,99 and for left parenthesis 4D, so the value will be 97994D, since D is negative it will be -97994. Till this point I am clear, But you said it will be displayed as 9799M, but M is D4, but we are storing as 4D which is (, so the value as per my understanding should be 9997(.
AM I Nissing something here? |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
zoned decimal definitons:
Code: |
value of
last byte
======
DEC VAL
+0 {
+1 A
+2 B
+3 C
+4 D
+5 E
+6 F
+7 G
+8 H
+9 I
-0 }
-1 J
-2 K
-3 L
-4 M
-5 N
-6 O
-7 P
-8 Q
|
M = -4 |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
|
|
|
|
COBOL won't directly display a COMP-3 or COMP value. They are converted to USAGE DISPLAY as part of the DISPLAY statement. However, in doing so COBOL does not do anything with the sign, so X'97994D' is converted to 'F9F7F9F9D4' when displayed. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
thx for the post Robert.
I thought about the effect of posting my little chart,
without explanatory comments;
it would just confuse the TS.
your comment has avoided that. |
|
Back to top |
|
|
saurabh39 Warnings : 1 Active User
Joined: 11 Apr 2008 Posts: 144 Location: Jamshedpur
|
|
|
|
@Roberts - Thanks for the comment...Now I am clear about it. |
|
Back to top |
|
|
saurabh39 Warnings : 1 Active User
Joined: 11 Apr 2008 Posts: 144 Location: Jamshedpur
|
|
|
|
One more question..........1234 will be represented as 4D2...which is fine...but -1234 is represented as FB2E. I checked one of the old topic...and dick replied zero minus 4D2 will give FB2E...which indeed is correct......but i did not get why i need to subtract with zero...my understanding was negative number will be stored as two complement.....so why should it 4D2..be subtracted from zero instead of binary equivalent of 4D2 being subracted from its two complement. |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
|
|
|
|
Dick gave a shortcut method. Technically, what you do is flip each bit of the value (zero becomes one, one becomes zero) so the zero becomes F, 4 (0100 in binary) becomes B (1011 in binary), D (1101 in binary) becomes 2 (0010 in binary) and 1 (0010) becomes D (1101). However, you then add 1 to the value so the D becomes E (1110) (again, for technical reasons beyond the scope of a post). Hence 04D2 becomes FB2E. |
|
Back to top |
|
|
saurabh39 Warnings : 1 Active User
Joined: 11 Apr 2008 Posts: 144 Location: Jamshedpur
|
|
|
|
Thanks again Robert. The mistake I was doing - I was trying to find out complement of 4D2, instead of 04D2 as a result I was not getting intended result.
Just to rephrase, you first found out one complement of a number and then added one, which is another way of finding two's complement.
But your quote -
Quote: |
(again, for technical reasons beyond the scope of a post). |
confused me, What information are you withholding and terming as beyond the scope. |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
|
|
|
|
Basically, the negative values should be ones' complement; however, since two's complement allows addition and subtraction to proceed without requiring looking at the signs of the numbers, IBM used it for their negatives. Also, one's complement allows for two representations of the value zero while two's complement does not -- which can cause problems as you can imagine. But you do have to remember to add that 1 after flipping all the bits.
I didn't intend to withhold information -- but we don't need to discuss AND gates to talk about how COBOL IF logic works. There's a lot of background to most of these questions that is noise (that is, adds to the length of the answer without increasing the clarity of the answer). Anytime you want more of the background, though, I'll provide as much as I can. |
|
Back to top |
|
|
|