Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Storage Requirements 2

Status
Not open for further replies.

claudeb

Programmer
Nov 23, 2000
140
CA
Hello
i understand that Pic 9(13)comp-3, Pic S9(14)comp-3 require 7 and 8 bytes of storage respectively. i don't see why Pic S9(12)comp, Pic S9(13)comp and Pic S9(14)comp require 6 bytes of storage.
Any hint ? I read Michael Mattias's article, but still i need some light.
 
Anyone answering this question will need to know:

Which compiler are you using?

Tom Morrison
 
Hi Claude,

When using COMP with mainframe COBOL compilers the number of 9s specified in the PIC determines the number of storage positions allocated to the data element (i.e., the # of bytes). The ranges and their assigned bytes are as follows:

Code:
              # of 9s           # of bytes 
               1 - 4           2 (halfword)
               5 - 9           4 (fullword)
              10 - ?           8 (doubleword)

Depending on the compiler options chosen (NUMCLS, NUMPROC, I think), there is a distinction that the compiler makes between the capacity of the field and the accessibility of the data in the field. For example, although the field has a capacity to hold 5 digits worth of data, but you code only 2 9s, 32,043 would be truncated to 43! So caution is advised when using COMP. Now, the appropriate option choice can result in nullifying the truncation, allowing a number like 32,043 to reside unmolested in the field.

You getting all this Claude? I know I'm getting dizzy. X-)

So getting back to your original ques, so long as you don't expect more than 12 digits worth of data in the field, or you select the right compile option, you can do it.

The other ques is: why would anyone use one 9 when 4 is the max allowable for a halfword? Well, I guess when you specify a field that represents the # of days in a week, 5 9s may be confusing. Who knows? It is what it is.

Regards, Jack.
 
The pic S9(12) would have a maximum value of 999,999,999,999.
The binary or COMP value would be x'E8D4A50FFF'
This requires five bytes of memory. Since the high-order bit is used as part of the numeric value the sign will require an additional byte, i.e. this requires six bytes.

The pic S9(13) would have a maximum value of 9,999,999,999,999.
The binary or COMP value would be x'09184E729FFF'
This requires six bytes of memory.

The pic S9(14) would have a maximum value of 99,999,999,999,999.
The binary or COMP value would be x'5AF3107A3FFF'
This requires six bytes of memory.

Depending on the system and the compiler you are using the actual amount of memory allocated for the above items will vary. On the mainframe with COBOL II each of the above would be allocated with eight (8) bytes of memory.

Now here is an interesting item worth considering...
A pic 9(8) with a value of 12,648,430 is interesting.
The binary or COMP value would be x'C0FFEE' and...
I think it is time for a break, as in C0FFEE break...
Saginaw
helpdesk@simotime.com
 
hello hello
How did you find E8D4A50FFF for 999 999 999 999 ?
I get D4A50FFF
If i can understand that , i will be happy. I know that i don't need to worry about the storage on a mainframe. as slade said it, it is 2, 4 or 8.
1101 0100 1010 0101 0000 1111 1111 1111
D 4 A 5 0 F F F
Thanks a lot.
 
You have binary truncation.

The maximum integer value that may be represented in 31 bits [the 32nd bit is used for sign] is 2[sup]31[/sup] - 1. The number of decimal digits this represents may be found by taking the common (base 10) logarithm of this number.

log (2[sup]31[/sup] - 1) approximately = log (2[sup]31[/sup]) = 31 log 2 approximately = 31 * 0.3 = 9.3

Therefore a 32 bit signed integer may represent at most 9 decimal digits.

How many bits does it take to represent 12 decimal digits?

n log 2 = 12
n = (12 / 0.30103) = 39.9

Answer: it takes 40 bits to represent 12 decimal digits. Add on a sign bit if you want to represent a signed 12 decimal digit number. Therefore:
999999999999[sub]10[/sub]= E8D4A50FFF[sub]16[/sub]
Tom Morrison
 
claudeb,
Hopefully Tom has answered your question. Here is some additional information.
If you get x'D4A50FFF' as the hex value for 999,999,999,999 then you have truncated the high-order byte. I suspect you may be running Windows/98 on a PC and are using the calculator function. If this is true then notice the hex-function of the calculator for Windows/98 only supports a maximum field size of a double-word (i.e. four bytes) and this will truncate the high-order byte and give you the results you are getting. The hex calculator in Windows/2000 supports a Qword and gives the correct answer of x'E8D4A50FFF'

Saginaw
helpdesk@simotime.com
 
That is exactly the case. How was the COFFEE break ?. Thanks a lot.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top