View previous topic :: View next topic |
Author |
Message |
yadav2005 Intermediate

Joined: 10 Jan 2005 Posts: 348 Topics: 144
|
Posted: Thu Feb 15, 2007 11:29 pm Post subject: COMP-3 bytes calculation needed |
|
|
I have a variable defined as below:
Code: |
01 A PIC S9(05)V999 COMP-3.
|
I am dislaying the length of the variable by using:
Code: |
DISPLAY 'LENGTH OF A :' LENGTH OF A.
|
And the Output is:
Code: |
LENGTH OF A :000000005
|
Now the length is 5 bytes.How is the length calculated as 5 bytes.My understanding is that each digit occupies 0.5 bytes so , 5 + 3 = 8 * 0.5 = 4 bytes since there are 9(05) and 999 so total i am expecting 8 that is why i am multipliying 8 by 0.5.Why should it take 5 bytes as the V does not occupy space and S (Sign) is stored in the last nibble byte.
Please help me in understanding why is it 5 bytes and how should we calculate the bytes for a COMP-3 Variable. |
|
Back to top |
|
 |
programmer1 Beginner
Joined: 18 Feb 2004 Posts: 138 Topics: 14
|
Posted: Thu Feb 15, 2007 11:41 pm Post subject: |
|
|
Quote: |
S (Sign) is stored in the last nibble byte
|
What do we mean by this ?
Any COMP-3 variable would reserve half byte for the sign. _________________ Regards,
Programmer |
|
Back to top |
|
 |
yadav2005 Intermediate

Joined: 10 Jan 2005 Posts: 348 Topics: 144
|
Posted: Fri Feb 16, 2007 1:06 am Post subject: |
|
|
Thanks for your reply.
So it should take 4 + 0.5(For Sign) = 4.5 bytes totally ,why does it take 5 bytes .Can you please explain me this? |
|
Back to top |
|
 |
dbzTHEdinosauer Supermod
Joined: 20 Oct 2006 Posts: 1411 Topics: 26 Location: germany
|
Posted: Fri Feb 16, 2007 4:17 am Post subject: |
|
|
you are correct: 4.5 bytes. You can not define a field with 1/2 bytes, the left most 1/2 byte of the 5 is not used.
you round up. _________________ Dick Brenholtz
American living in Varel, Germany |
|
Back to top |
|
 |
yadav2005 Intermediate

Joined: 10 Jan 2005 Posts: 348 Topics: 144
|
Posted: Fri Feb 16, 2007 4:40 am Post subject: |
|
|
Thanks Dick,
I am very much clear now and it is wonderful answer from you.
You are great. |
|
Back to top |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12382 Topics: 75 Location: San Jose
|
|
Back to top |
|
 |
yadav2005 Intermediate

Joined: 10 Jan 2005 Posts: 348 Topics: 144
|
Posted: Fri Feb 16, 2007 7:47 am Post subject: |
|
|
Dick,
I have a question as the storage required bytes is 3 bytes in both the cases.
Code: |
01 A PIC 9(04) COMP-3 VALUE 123.
01 B PIC 9(04) COMP-3 VALUE 1234.
|
Why is it 3 bytes ? My understanding is 4 * .5 = 2 bytes .Since sign is not there we need not add .5 byte to form 2.5 and then round off to 3 bytes .Can u please explain why it is 3 bytes and my understanding is if a COMP-3 variable is declared as signed then the sign is stored on the last 4 bits.
Please help me in understanding how both the variables are stored internally for both A & B. |
|
Back to top |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12382 Topics: 75 Location: San Jose
|
Posted: Fri Feb 16, 2007 7:53 am Post subject: |
|
|
yadav2005,
The COMP-3 data items always have the sign whether you define or not.
Also read the links in the above post of mine paying attention to section 1.3.4.7
Kolusu _________________ Kolusu
www.linkedin.com/in/kolusu |
|
Back to top |
|
 |
vak255 Intermediate

Joined: 10 Sep 2004 Posts: 384 Topics: 79
|
Posted: Fri Feb 16, 2007 3:01 pm Post subject: |
|
|
Thats a news for me. good, I need to refresh. |
|
Back to top |
|
 |
ranga_subham Intermediate

Joined: 31 Jan 2006 Posts: 255 Topics: 72
|
Posted: Sun Feb 25, 2007 3:17 am Post subject: |
|
|
Kolusu,
Quote: |
The COMP-3 data items always have the sign whether you define or not.
|
how to move negative value into a comp-3 field without defining "S" (sign)?
Ex: 9(4) comp-3 - would this hold negative value too?
Please explain.
Thanks. _________________ Ranga
*****
None of us is as smart as all of us - Ken Blanchard |
|
Back to top |
|
 |
dbzTHEdinosauer Supermod
Joined: 20 Oct 2006 Posts: 1411 Topics: 26 Location: germany
|
Posted: Sun Feb 25, 2007 6:32 am Post subject: |
|
|
Ranga,
PIC 9(4) COMP-3 is telling the compiler, always ignore the sign, value will be treated as positive.
PIC S9(4) COMP-3 is telling the compiler, there is always a valid sign associated with with the value, account for it in all math manipulations and edits. _________________ Dick Brenholtz
American living in Varel, Germany |
|
Back to top |
|
 |
ranga_subham Intermediate

Joined: 31 Jan 2006 Posts: 255 Topics: 72
|
Posted: Fri Mar 09, 2007 2:51 am Post subject: |
|
|
Thanks dbzTHEdinosauer. I think, I got it. _________________ Ranga
*****
None of us is as smart as all of us - Ken Blanchard |
|
Back to top |
|
 |
Nithisha Beginner
Joined: 27 May 2006 Posts: 23 Topics: 13 Location: Pune
|
Posted: Fri Mar 09, 2007 6:04 am Post subject: Comp-3 Calculation |
|
|
Hi
friend
we calculate the comp-3 by (N/2)+1
where N is number of total byte. So according to you question. You have
S9(5)v999.
Number of byte is 8
calulation : (8/2)+1= 5.
Hence you are getting 5 byte.
some stands what i have come accross for COMP
Code: |
9(1) - 9(4) =2 BYTE
9(5)- 9(8) = 4 BYTE
9(9) -9(18)= 8 byte.
|
thanks
Nithisha |
|
Back to top |
|
 |
naveen Beginner

Joined: 03 Dec 2002 Posts: 90 Topics: 31
|
Posted: Wed Mar 14, 2007 4:02 am Post subject: |
|
|
Starting half byte is Zero Padded in comp-3 in case of even number of bytes.
Example is S9(6) COMP-3 will take 4 bytes.
Number 456789 in COMP-3 , is stored in following manner: 0456789C
Remeber the "0" being padded at the start. |
|
Back to top |
|
 |
|
|