View previous topic :: :: View next topic

Author 
Message 
Talent
New User
Joined: 10 Jun 2005 Posts: 1




Hi all,
If i have a field PIC 9(8) comp .... having value '4020722' , how will it be stored in memory..... will it be in its binary form i.e. 1111 1010 1011 0011 1110 0010 or something else.
I need to write a Conversion Program in C++ that will convert an ASCII number to EBCDIC comp value. Can someone help me with this.
Thanks in advance. 

Back to top 




Allu
New User
Joined: 08 Jun 2005 Posts: 4




Hi Talent.......
What you guessed is correct, It stores in Binary only.
Actually, BINARY, COMP, and COMP4 are synonyms on all platforms.
Binary format numbers occupy 2, 4, or 8 bytes of storage. If the PICTURE clause specifies that the item is signed, the leftmost bit is used as the operational sign. A binary number with a PICTURE description of four or fewer decimal digits occupies 2 bytes; five to nine decimal digits, 4 bytes; and 10 to 18 decimal digits, 8 bytes. Binary items with nine or more digits require more handling by the
compiler.
Thanks
Allu. 

Back to top 


Allu
New User
Joined: 08 Jun 2005 Posts: 4




Hi Talent.......
What you guessed is correct, It stores in Binary only.
Actually, BINARY, COMP, and COMP4 are synonyms on all platforms.
Binary format numbers occupy 2, 4, or 8 bytes of storage. If the PICTURE clause specifies that the item is signed, the leftmost bit is used as the operational sign. A binary number with a PICTURE description of four or fewer decimal digits occupies 2 bytes; five to nine decimal digits, 4 bytes; and 10 to 18 decimal digits, 8 bytes. Binary items with nine or more digits require more handling by the
compiler.
Thanks
Allu. 

Back to top 


mmwife
Super Moderator
Joined: 30 May 2003 Posts: 1592




Hi Guys,
Here's what I get for the binary value of dec 4020722:
0011 1101 0101 1001 1111 0010
What Allu says about the sign is correct but can be misleading. A negative number is represented as the "twos complement" of the positive.
The "twos complement" calculation process follows:
Change every bit in the field containing the pos number to its complement, i.e. ones to zeros, zeros to ones. Add 1 to the low order bit.
Some examples:
A binary 1 is 0000 0001 Its negative is 1111 1111
A binary 2 is 0000 0010 Its negative is 1111 1110
If these values were in 4 byte fields the positive's zeros would extend to the left filling the field, as you know.
However, the negative's ones would extend to the left filling the field. 

Back to top 



