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

comp-1 and comp-2 values


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Ambili S

Active User


Joined: 06 Sep 2007
Posts: 112
Location: India

PostPosted: Tue Jul 20, 2010 10:57 am
Reply with quote

Hi

The PIC clause for comp-1 and comp-2 are :

COMP-1 : SV9(8)ES99

COMP-2: SV9(17)ES99

I want to know how 'S' is represented in the exponential part ( ES99) . Under what scenario will it show negative ( - ) ? Or will it be +ve always (i.e.blanks).

I mean will it ever show something like ( -.12300000E-03) , for an input say -123 moved to comp-1 and comp-2 ?
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Tue Jul 20, 2010 1:20 pm
Reply with quote

Internal representation
Back to top
View user's profile Send private message
Ambili S

Active User


Joined: 06 Sep 2007
Posts: 112
Location: India

PostPosted: Tue Jul 20, 2010 1:58 pm
Reply with quote

I had seen this link earlier also,but couldn't figure out how the comp-1 internal representation came to 43 4D 20 00 for +1234.

could you please help me with it ?
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Tue Jul 20, 2010 4:34 pm
Reply with quote

well, you need to start at basics.

floating-point

COMP-1 and COMP-2 are internal-floating point. They do not have picture clauses

discussions on external floating point are referenced in the above link.

Quote:
could you please help me with it ?


you need to spend some time reading the manual.
I am not going to paraphrase it for you.
Back to top
View user's profile Send private message
Ambili S

Active User


Joined: 06 Sep 2007
Posts: 112
Location: India

PostPosted: Wed Jul 21, 2010 10:34 am
Reply with quote

Hi

Thanks for the links . I did go through them and it helped me.

I could understand the internal representation of value +1234 in binary is 04 D2 . But i couldn't figure out how the represenation for -1234 would be determined ?

Could you please help.
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: Wed Jul 21, 2010 3:56 pm
Reply with quote

Hex C3 4D 20 00 -- the sign bit is turned on to denote the negative value. The 43 4D 20 00 remains exactly the same.
Back to top
View user's profile Send private message
Ambili S

Active User


Joined: 06 Sep 2007
Posts: 112
Location: India

PostPosted: Thu Jul 22, 2010 8:49 am
Reply with quote

This is were i am confused.

For Binary , value of +1234 has internal representation as 04 D2 , coz the binary value would be 0000 0100 1101 0010.

But for value -1234 how is it FB 2E.

Secondly for same value in Comp-1 how is it represented as 43 4D 20 00 ?
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 Jul 22, 2010 9:14 am
Reply with quote

Hello,

Quote:
But for value -1234 how is it FB 2E.
Because FB2E is the result when 4D2 is subtracted from zero. . .

You can verify this (and do other similar experiments) using the hex calculator on your pc.
Back to top
View user's profile Send private message
Ambili S

Active User


Joined: 06 Sep 2007
Posts: 112
Location: India

PostPosted: Thu Jul 22, 2010 1:37 pm
Reply with quote

ya i understood now how -1234 is FB2E , but couldn't understand how the Comp-1 representation is 43 4D 20 00
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 Jul 22, 2010 5:00 pm
Reply with quote

Since you obviously have a reading problem (this is explained in the COBOL manuals as you have been repeatedly told), I'll elaborate:

The first bit is the sign bit -- 0 means positive, 1 means negative.

The next seven bits are the exponent. For technical reasons, IBM stores the exponent in excess-64 notation (meaning they add 64 or hex 40 to the actual exponent). Hence 43 minus 40 is 3 (even in hex), so the exponent is 3.

The remaining 24 bits represent the mantissa of the floating point number. So the 4D2000 represents the 1234. The decimal point is implied after the first digit -- as IBM explicitly states in the manual.

So positive 1.234 times 10 raised to the third power is ... 1234.
Back to top
View user's profile Send private message
Ambili S

Active User


Joined: 06 Sep 2007
Posts: 112
Location: India

PostPosted: Fri Jul 23, 2010 11:12 am
Reply with quote

Thanks Robert for the explanantion.

You said this is explained in the COBOL manuals ,

Could you please let me know which COBOL manual should be referred.
Back to top
View user's profile Send private message
Ambili S

Active User


Joined: 06 Sep 2007
Posts: 112
Location: India

PostPosted: Tue Sep 28, 2010 6:59 pm
Reply with quote

Hi Robert ,

In your above reply you have mentioned For technical reasons, IBM stores the exponent in excess-64 notation (meaning they add 64 or hex 40 to the actual exponent). Hence 43 minus 40 is 3 (even in hex), so the exponent is 3.


Could you please explain how 43 is obtained ?
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: Tue Sep 28, 2010 7:25 pm
Reply with quote

Start with the value. Shift the decimal point left or right until the decimal point is behind the first digit. The number of shifts is the exponent value. If you shifted left, the value is positive. If you shifted right, the value is negative.

1234 requires 3 shifts to be 1.234, hence the 3 -- and since the shifts were to the left, it is a positive three.

.0012345 requires 3 shifts to be 1.234, so again a 3 -- but this time the shifts were to the right, so the value is negative 3.

IBM adds the 40 (hex) automatically -- so +3 added to 40 becomes 43. 40 hex minus 3 is 3D so .001234 expressed as a COMP-1 value is 3D 4D 20 00
Back to top
View user's profile Send private message
Ambili S

Active User


Joined: 06 Sep 2007
Posts: 112
Location: India

PostPosted: Wed Sep 29, 2010 11:12 am
Reply with quote

That was really helpful Robert.Thanks a lot icon_razz.gif
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 -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts INCLUDE OMIT COND for Multiple values... DFSORT/ICETOOL 5
No new posts Replace Multiple Field values to Othe... DFSORT/ICETOOL 12
No new posts Null values are considered in Total c... DFSORT/ICETOOL 6
No new posts COBOL - Move S9(11)v9(7) COMP-3 to -(... COBOL Programming 5
No new posts Converting ASCII values to COMP-3 (ZD... JCL & VSAM 2
Search our Forums:

Back to Top