View previous topic :: View next topic
|
Author |
Message |
Amit Manas Dubey Currently Banned New User
Joined: 15 Dec 2006 Posts: 22 Location: Mumbai
|
|
|
|
Hi
Can somebody tell me how can we calculate the space utilized by COMP variables in COBOL ?
For example S9(8) COMP - Takes 4 bytes ...Is there a way this can be calculated ?? Also, is there a diff in the no of bytes used by signed and unsigned numeric variables.
Thanks
Amit |
|
Back to top |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
Amit Manas Dubey wrote: |
Can somebody tell me how can we calculate the space utilized by COMP variables in COBOL ? For example S9(8) COMP - Takes 4 bytes ...Is there a way this can be calculated ?? |
Comp is binary and the assembler opcode that does binary arithmetic are register instructions. Register instructions either deal with full words or half words. The registers themselves are full words. Full words are 4 bytes long.
Quote: |
Also, is there a diff in the no of bytes used by signed and unsigned numeric variables. |
In binary (comp) fields, only the one high bit signifies the sign, no extra length needed.
In packed (comp3) fields the last half byte signifies the sign, always there and no extra length needed. |
|
Back to top |
|
|
Amit Manas Dubey Currently Banned New User
Joined: 15 Dec 2006 Posts: 22 Location: Mumbai
|
|
|
|
I saw the manuals....As I understand say S9(4) COMP - can have 9999 as Max value - this when converted to Binary is 10011100001111 + 1 bit for sign = 15 bits .....This will take 2 bytes = 16 bits........
Is my understanding correct ? |
|
Back to top |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
Amit Manas Dubey wrote: |
I saw the manuals....As I understand say S9(4) COMP - can have 9999 as Max value - this when converted to Binary is 10011100001111 + 1 bit for sign = 15 bits .....This will take 2 bytes = 16 bits........
Is my understanding correct ? |
Kinda.....Some compiler (or LE) thingy will force the max number to be no greater than the number of digits specified - S9(4) means 9999 is max. But without that setting, 32767 (7FFF) is possible. |
|
Back to top |
|
|
Amit Manas Dubey Currently Banned New User
Joined: 15 Dec 2006 Posts: 22 Location: Mumbai
|
|
|
|
Pls explain a little more...You mean to say that the storage can be coded in Hexadecimal as well...Okies....why not FFFF ?? is it because of signed stuff - 32767 - 0 - + 32767 ?
Pls elaborate !! |
|
Back to top |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
Amit Manas Dubey wrote: |
Pls explain a little more...You mean to say that the storage can be coded in Hexadecimal as well...Okies....why not FFFF ?? is it because of signed stuff - 32767 - 0 - + 32767 ?
Pls elaborate !! |
Actually it is -32768 (FFFF) +32767 (7FFF) - remember the high bit is the sign.
comp-val pic s9(4) comp.
hex-val redefines comp-val pic x(4).
move x'1000' to hex-val.
display comp-val.
|
|
Back to top |
|
|
Amit Manas Dubey Currently Banned New User
Joined: 15 Dec 2006 Posts: 22 Location: Mumbai
|
|
|
|
Thanks a lot Tom...
I am clear on this now...Just curious to know - how do you revert so fast on these posts ? unless u are addicted to this now !! |
|
Back to top |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
I'm not quite that fast.... |
|
Back to top |
|
|
sandip_mainframe Warnings : 2 New User
Joined: 20 Sep 2006 Posts: 63 Location: pune
|
|
|
|
hi,
usage comp it is used for numeric value stored in pure binary form.
PIC S9(1) TO PIC S9(4) IT TAKES 2 BYTES = HALF WORD = 16 BITS
PIC S(5) TO PIC S9(9) IT TAKES 4 BYTES = FULL WORD = 32 BITS
PIC S9(10) TO PIC S9(19) IT TAKES 8 BYTES =DOUBLE WORD = 64 BITS.
SANDIP WALSINGE. |
|
Back to top |
|
|
Selvamani
New User
Joined: 19 Dec 2006 Posts: 21 Location: California
|
|
|
|
Sandeep,
I remember that 1 byte = 4 bits. If this is correct, Then your calculation needs to be relooked.
Am I correct? |
|
Back to top |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
Selvamani wrote: |
I remember that 1 byte = 4 bits. |
No, one byte is 8 bits
no |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello,
1 byte = 8 bits. . .
For example the letter A is made up of these bits
1100 0001 which is read as C1. The numeral 9 is 1111 0101 (F9). |
|
Back to top |
|
|
UmeySan
Active Member
Joined: 22 Aug 2006 Posts: 771 Location: Germany
|
|
|
|
Hi !
Coming back to main question. As Sandip wrote it's like:
PIC 9 to 9(4) -> 2 Bytes
PIC 9(5) to 9(9) -> 4 Bytes
PIC 9(10) to 9(18) -> 8 Bytes
With binary, you only have halfbyte, fullbyte and douplebyte.
@Sandip: S9(19) ??? Are you really shure ???
Just a little tip. Code alle your desired field in al little programm.
Like PIC 9(01) comp / PIC 9(02) comp / and so on.
Compile your programm. Then have a look at the listing.
PIC S9(9) COMP. BLW=00000+F45,0000035 4C
So here you could see, that S9(9) resides in a four byte field. Just 4C.
Regards, Umeysan |
|
Back to top |
|
|
|