View previous topic :: View next topic
|
Author |
Message |
nandakumar Warnings : 2 New User
Joined: 05 May 2005 Posts: 50
|
|
|
|
Hi,
can anybody plz tell me:
In cobol programming if we define a numeric data in comp-3 it is stored interenally as packed decimal digits.is it right,then what does packed decimal digits means. |
|
Back to top |
|
|
j_prameela2000
New User
Joined: 01 Jun 2005 Posts: 28 Location: Chennai
|
|
|
|
Yes u are correct. One to 16 bytes may be used to store a sequence of decimal digits representing an arithmetic value. A pattern of four bits is defined for each decimal digit. Since a byte consists of eight bits, upto two decimal digits may be packed into one byte and one half of a byte is reserved for tyhe sign + or - of the number. Eg. to represent +5, one byte is needed which is denoted as 5+ where 5 holds the binary value 0101 and + holds the binary bit pattern value 1100. |
|
Back to top |
|
|
senthilkumar selvaraju
New User
Joined: 30 May 2005 Posts: 16
|
|
|
|
packed decimal means hexa decimal value. |
|
Back to top |
|
|
Sangram
New User
Joined: 08 Jun 2005 Posts: 7
|
|
|
|
[color=darkblue]Packed decimal is nothing but the hexadecimal equivalent of the data that you have entered. It will not be visible when the file having packed decimal data is opened in edit mode unless you use a HEX ON. It is used to provide optimum storage. A variable with PIC X(5) COMP-3 will occupy only 3 bytes in the storage memory. |
|
Back to top |
|
|
subhasis_50
Moderator
Joined: 09 Mar 2005 Posts: 363 Location: Earth
|
|
Back to top |
|
|
senthilkumar selvaraju
New User
Joined: 30 May 2005 Posts: 16
|
|
|
|
Hi sangram,
Alphanumeric picture clause is not possible in comp-3 usage. As per your example, you mention that it takes 3 bytes storage. it's wrong. it takes 4 bytes because 3 bytes for value and one byte for sign. If you feel and wrong in my answer, please send me |
|
Back to top |
|
|
frame_kan
New User
Joined: 03 Jun 2005 Posts: 5
|
|
|
|
Hi
I think it will take 3 bytes 2.5 +.5 .As far as alphanumeric picture clause is concern i am not sure whether we can define it or not
Frame |
|
Back to top |
|
|
j_prameela2000
New User
Joined: 01 Jun 2005 Posts: 28 Location: Chennai
|
|
|
|
It is (n+1)/2 for odd digit and (n/2 + 1) for even digit. Try this out. You will get exactly how many bytes does the variable occupies. If any alterations in my answer, correct it. |
|
Back to top |
|
|
Sangram
New User
Joined: 08 Jun 2005 Posts: 7
|
|
|
|
Hi Senthilkumar,
COMP 3 usage is usually done for signed integers. Thats the most common and optimum use of comp 3 . The storage space for COMP 3 is calculated by using the formula (n+1)/2 where 'n' stands for the actual size of the variable. For e.g. - a variable of PIC X(5) COMP-3 will take 3 bytes of storage where the 5 bytes of the variable will be stored in 2.5 bytes of actual storage and the sign will be stored in 0.5 bytes of actual storage. The sign is always stored in the last half byte of the actual storage. If you need further info, drop in a reply. |
|
Back to top |
|
|
worthy2005
New User
Joined: 09 Mar 2005 Posts: 17 Location: Shanghai,China
|
|
|
|
j_prameela2000 wrote: |
Eg. to represent +5, one byte is needed which is denoted as 5+ where 5 holds the binary value 0101 and + holds the binary bit pattern value 1100. |
But how about -5? '+' represents 1100, but '-' represents what? Thanx! |
|
Back to top |
|
|
thanooz
New User
Joined: 28 Jun 2005 Posts: 99
|
|
|
|
hi
comp-3 is used store data in packed decimal format.it is hexa decimal storage.the n/2 bytes for actuval value 1/2 byte for sign representation
if its sign is positive last halfbyte have hexa c,negative d,unsigned f .
thanooz |
|
Back to top |
|
|
|