View previous topic :: View next topic
|
Author |
Message |
guruji
New User
Joined: 13 Apr 2007 Posts: 61 Location: Chennai
|
|
|
|
Hi,
Could you please tell me How much bytes do S9(7)V99 COMP-3 occupy?
could you please explain the same?
Thanx,
reni |
|
Back to top |
|
|
radha reddy
New User
Joined: 15 May 2008 Posts: 9 Location: hyderabad
|
|
|
|
It occupies 5 bytes.
no of 9's = 9
(9+1)/2 = 5 |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello,
5 bytes.
Quote: |
There are 2 digits for each character position, except for the trailing character position, which is occupied by the low-order digit and the sign. |
The quote is from the COBOL Language Reference available via the IBM Manuals link at the top of the page. |
|
Back to top |
|
|
shakawa
New User
Joined: 11 Jun 2008 Posts: 1 Location: Beijiing
|
|
|
|
Hi dick,
So you mean the sign also occupys one byte, do you? |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
Dick,
it would be so much easier for the OP if you would just teach him what he needs to learn. Apparently he can web-browse only this site - thus no access to a site like IBM, where he could actually learn something on his own. he could learn something here if he would search... but, again, easier to ask than look. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello shakawa and welcome to the forums,
Quote: |
So you mean the sign also occupys one byte, do you? |
No, the sign in a packed-decimal (comp-3) number occupies the low-order nibble (1/2 byte) of the low order byte.
All of the information is available in the COBOL documentation i mentioned before (linked via "IBM Manuals" at the top of the page). |
|
Back to top |
|
|
surya.kalyan
New User
Joined: 09 Jan 2007 Posts: 20 Location: Mumbai
|
|
|
|
Here is a short representation of how data is stored in comp-3 fields.
ASSUME THE PICTURE CLAUSE IS 9(4) COMP-3. Number of bytes = (4+1)/2 = 3 (rounded).
So, At Max 4 digits can be accomodated.
If the number is +1234.It is stored as,
(In Hex) 01 23 4C
If the number is -1234.It is stored as,
(In Hex) 01 23 4D
C for + sign and D for -sign.
If the number is +123. It is stored as
(In Hex) 00 12 3C
If the number is -123. It is stored as
(In Hex) 00 12 3D.
One byte will store two digits. And the sign is stored in the last nibble.
We cannot allocate nibbles(half byte).
So, thats the reason for the formula
(n+1)/2.
Suggest or correct me if I am wrong somewhere. |
|
Back to top |
|
|
hanucob
New User
Joined: 15 Jul 2008 Posts: 3 Location: bangalore
|
|
|
|
The formula for it is INT(N/2+1) |
|
Back to top |
|
|
radha reddy
New User
Joined: 15 May 2008 Posts: 9 Location: hyderabad
|
|
|
|
Hi Hanucob,
There is correction to your formula.
For comp-3 formula is (N+1)/2
Sign byte occupies only 1/2 byte.
Thanks,
Radha |
|
Back to top |
|
|
surya.kalyan
New User
Joined: 09 Jan 2007 Posts: 20 Location: Mumbai
|
|
|
|
Hi Radha
I feel both of them are correct. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
surya.kalyan,
Quote: |
ASSUME THE PICTURE CLAUSE IS 9(4) COMP-3. Number of bytes = (4+1)/2 = 3 (rounded
|
since your picture clause does not include a sign, a lot of your explanation was incorrect: there is no way you could store a negative value in that field.
other than that, you post was pretty good. |
|
Back to top |
|
|
radha reddy
New User
Joined: 15 May 2008 Posts: 9 Location: hyderabad
|
|
|
|
Hi Surya,
For S9(7)V99 COMP-3
When we use N/2+1 we will have 9/2 = 4.5
4.5 + 1 = 5.5
rounding off will give 6 bytes
When we use formula (N + 1)/2
We will get (9+1)/2 = 10/2 = 5 bytes.
So (N+1)/2 or (N/2 +1/2) is the correct formula.
Correct me if I am wrong.
Thanks,
Radha |
|
Back to top |
|
|
surya.kalyan
New User
Joined: 09 Jan 2007 Posts: 20 Location: Mumbai
|
|
|
|
Quote: |
S9(4) COMP-3. since your picture clause does not include a sign, a lot of your explanation was incorrect: there is no way you could store a negative value in that field. |
Yup, it should have been S9(4) COMP-3. |
|
Back to top |
|
|
surya.kalyan
New User
Joined: 09 Jan 2007 Posts: 20 Location: Mumbai
|
|
|
|
Hi radha,
Quote: |
The formula for it is INT(N/2+1) |
INT is not rounding off.
Its extracting integer portion of a decimal number.
So,
INT(4.5) = 4 and not 5.
So, the formula is right according to me. |
|
Back to top |
|
|
ashimer
Active Member
Joined: 13 Feb 2004 Posts: 551 Location: Bangalore
|
|
|
|
You can use both ... if you are using N/2 + 1 then take only the integer part and if you are using (N+1) / 2 then roundoff ...
use both on S9(7)v99 and S9(10)v99 and see ..... physically sign occupies only half a byte ... |
|
Back to top |
|
|
Tom Goodhart
New User
Joined: 16 Jul 2008 Posts: 5 Location: Tennessee
|
|
|
|
Not coding the S for sign in the picture will cause values to be stored with "F" as the sign. An positive integer value which mathematically equal to +1.
If you code an even number of digits, the compiler will always make it 1 byte larger internally.
Thus,
S9(6) COMP-3 will take 4 bytes of storage
S9(7) COMP-3 will take 4 bytes of storage This is the preferred way as it is clear to anyone what was intended. |
|
Back to top |
|
|
Gousiya Mulla
New User
Joined: 02 Jun 2008 Posts: 87 Location: Bangalore
|
|
|
|
Quote: |
If the number is +1234.It is stored as,
(In Hex) 01 23 4C
|
Is this
(In Hex) 4D2 ? . Please clear me . |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
|
|
|
|
No:
Hex 0004D2 is the BINARY (or COBOL COMP) value of +1234.
Hex 01234C is the PACKED-DECIMAL (or COBOL COMP-3) value of +1234.
Hex F1F2F3F4 is the unsigned COBOL DISPLAY value of 1234.
Hex F1F2F3C4 is the signed COBOL DISPLAY value of +1234. |
|
Back to top |
|
|
Gousiya Mulla
New User
Joined: 02 Jun 2008 Posts: 87 Location: Bangalore
|
|
|
|
Robert ,
Understood .. Thax |
|
Back to top |
|
|
|