View previous topic :: View next topic
|
Author |
Message |
shammiullah
New User
Joined: 13 Jun 2005 Posts: 24
|
|
|
|
hi guyz,
01 filed1 pic s9(3) comp-3.
for this internally how many bytes will it take.do v have to use the formula n/2 + 1 or else n+1/2.if i'm using n/2 + 1 then it'll take 3 bytes. if i use the other formula it'll take 2 bytes.
so which one shuld be used. |
|
Back to top |
|
|
madhavihmk
New User
Joined: 31 Jan 2006 Posts: 8 Location: Chennai
|
|
|
|
Hi ,
U need to use n/2 + 1 |
|
Back to top |
|
|
nuthan
Active User
Joined: 26 Sep 2005 Posts: 146 Location: Bangalore
|
|
|
|
Hi,
If its even u have to use n/2 + 1
If its odd u have to use n+1/2 |
|
Back to top |
|
|
Hames
New User
Joined: 03 Oct 2005 Posts: 49
|
|
|
|
Hi nuthan,
You have to use the formula n/2 + 1.
If n is odd, you have to round the answer to the nearest integer.
that is if n/2 + 1 = 2.5 then you round it to 3. |
|
Back to top |
|
|
DavidatK
Active Member
Joined: 22 Nov 2005 Posts: 700 Location: Troy, Michigan USA
|
|
|
|
shammiullah,
Let?s start out with some truths.
1 - The compiler always allocates comp-3 fields in full bytes (unless you?re using a Burroughs computer that allocates in 1/2 bytes, I?ll bet most of you don?t even know what a Burroughs computer is! )
2 - Each digit in the PIC occupies 1 half byte, or .5 full bytes
3 - The sign will occupy 1 half byte or .5 full bytes. (Even if it is unsigned, there is always a sign allocation)
Example: PIC S9(3) COMP-3.
PIC S9(3) COMP-3 will occupy 3 half bytes or 1.5 full bytes.
The sign occupies 1 half byte or .5 full bytes.
Therefore PIC S9(3) COMP-3 will occupy 2 full bytes.
Another example: PIC 9(4) COMP-3
A PIC 9(4) COMP-3 will occupy 4 half bytes, or 2 full bytes.
The sign (even when unsigned) will occupy 1 half byte, or .5 full bytes.
The sum of these two is 5 half bytes, or 2.5 full bytes.
Remember, the compiler always allocates in full bytes, therefore, the compiler will add 1 half byte, so PIC 9(4) will occupy 6 half bytes or 3 full bytes.
You use the formula n/2 + ? rounded up to a full byte.
n/2 = number of full bytes the digits from the PIC will use
? = the number of full bytes the sign will use
rounded to full byte = number of full bytes the compiler adds to allocate in full bytes only. This will be 0, or .5 only
Hope this helps,
Dave |
|
Back to top |
|
|
|