|
|
| Author |
Message |
guruji Warnings : 1 New User
Joined: 13 Apr 2007 Posts: 41 Location: Bangalore
|
|
|
|
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 |
|
 |
References
|
Posted: Tue Jul 08, 2008 12:18 pm Post subject: Re: How much bytes do S9(7)V99 COMP-3 occupy? |
 |
|
|
 |
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
Global Moderator
Joined: 23 Nov 2006 Posts: 7337 Location: 221 B Baker St
|
|
|
|
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
Senior Member
Joined: 20 Oct 2006 Posts: 1343 Location: germany
|
|
|
|
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
Global Moderator
Joined: 23 Nov 2006 Posts: 7337 Location: 221 B Baker St
|
|
|
|
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: 12 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: 4 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: 12 Location: Mumbai
|
|
|
|
Hi Radha
I feel both of them are correct. |
|
| Back to top |
|
 |
dbzTHEdinosauer
Senior Member
Joined: 20 Oct 2006 Posts: 1343 Location: germany
|
|
|
|
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: 12 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: 12 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
Senior Member
Joined: 13 Feb 2004 Posts: 307 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 |
|
 |
|
|