View previous topic :: View next topic
|
Author |
Message |
krbabu
New User
Joined: 20 Feb 2004 Posts: 57
|
|
|
|
Hi ,
Can anybody tell me the differance between the packed decimal format and the binary decimal format. |
|
Back to top |
|
|
mcmillan
Site Admin
Joined: 18 May 2003 Posts: 1210 Location: India
|
|
|
|
Dear,
Binary Decimal is what you are defining as "COMP" and packed decimal is what you are thinking s "COMP-3"
In computational format data are stored in binary format and it occupies half / full / double word depending on the size of data.
In comp-3 format data are stored in 8421 decimal format and each digit occupies half-a-byte. |
|
Back to top |
|
|
krbabu
New User
Joined: 20 Feb 2004 Posts: 57
|
|
|
|
Hi Millan,
Thanks to your valuabel guidance, Can u give the example for the following number.
How can the number 126 stored in two formats , both the comp and comp-3.Can explain the internal format for 126 in both the cases. |
|
Back to top |
|
|
mcmillan
Site Admin
Joined: 18 May 2003 Posts: 1210 Location: India
|
|
|
|
Sure,
126 in COMP: 0000 0000 0111 1110 (2 bytes)
126 IN COMP-3: 0001 0100 0110 1111 (2 bytes) |
|
Back to top |
|
|
krbabu
New User
Joined: 20 Feb 2004 Posts: 57
|
|
|
|
Thanks millan,
i am in confusion about, how to mention the digits in comp-3 format. |
|
Back to top |
|
|
mmwife
Super Moderator
Joined: 30 May 2003 Posts: 1592
|
|
|
|
Hi Ravindra,
If you saw the 2 representations that McMillan presented in a dump they would look like this:
PIC 9(003) COMP-3 VALUE 126 ===> 126F
PIC 9(003) COMP VALUE 126 ===> 007E
The minus values might surprise you:
PIC S9(003) COMP-3 VALUE -126 ===> 126D
PIC S9(003) COMP VALUE -126 ===> FF82
If I did the math correctly.
Regards, Jack. |
|
Back to top |
|
|
mcmillan
Site Admin
Joined: 18 May 2003 Posts: 1210 Location: India
|
|
|
|
Hai,
Yes. It's exactly right Jack.
Quote: |
i am in confusion about, how to mention the digits in comp-3 format. |
Your Query is 126. hence I assumed it's unsigned positive.
In Comp-3 each digit occupies half-a-byte. Hence we need 1+1/2 bytes for 126. And also COMP-3 requires a half byte for sign digit. (Even if it's unsigned)
Hence totally we need 2 bytes.
Let's take 1, the equivalent 8421 code is: 0001
8421 code for 2 is: 0010
For 6 IT'S: 0110
Hence we get 0001 0010 0110
For Unsigned numeric the last nipple is: F
For Signed positive: C
For Negative: D
Equivalent 8421 code for F is : 1111
Hence our result is: 0001 0010 0110 1111
Is it Ok? |
|
Back to top |
|
|
philipraju Warnings : 1 New User
Joined: 16 Apr 2006 Posts: 29
|
|
|
|
hi,
im in small confusion in memory usage of comp,comp1,comp2.pls can any body explains by using same value for all. |
|
Back to top |
|
|
|