View previous topic :: View next topic
|
Author |
Message |
Vedam
New User
Joined: 24 Apr 2007 Posts: 23 Location: India
|
|
|
|
Hello,
I came across a document which says that a character(alphanumeric) variable is stored in one byte per one digit.
Can you please tell me how the value 'ABC' is stored?
A document says +1234 in character format is stored as follows:
The most significant bit is on the left:
Mode Byte 4 Byte 3 Byte 2 Byte 1
========= ======== ======== ======== ========
Character 00110001 00110010 00110011 00110100
what do the ones in bold signify?
Can you please explain how a 2 byte storage can store a maximum value of 99 for a character variable? |
|
Back to top |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
Yes, one byte per digit or character.
In hex, X'C1C2C3'.
Depending on the format, I'd tend to agree, ZD the most significant byte, PD the most significant half byte, binary the sing bit then the most significant bit.0011 is a binary 3, the binary string is X'31313334' which I would take as ASCII 1234.
Two bytes of storage can contain 00 thru 99 when usage is ZD, 0 thru 999 when usage is PD, 0 thru 32767 when usage is binary (plus 1 if you ignore the sign). |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Quote: |
A document says +1234 in character format is stored as follows:
The most significant bit is on the left:
Code: |
Mode Byte 4 Byte 3 Byte 2 Byte 1
========= ======== ======== ======== ========
Character 00110001 00110010 00110011 00110100 |
|
My recommendation would be to find a different document (at least as far as providing info for an IBM mainframe is concerned). The above is not for the IBM mainframe (EBCDIC character set), but rather how things are stored on UNIX and Win-based systems (ASCII). Care must be taken to make sure the document and the platform are the "same".
For your first question 'ABC' is stored as x'C1C2C3' which in binary is
'1100 0001 1100 0010 1100 0011' (on the mainframe). One byte of alphanumeric data is 2 hexadecimal digits (0-F) or 8 binary digits (0-1). Every 1-byte value is between x'00' and x'FF'.
Back to the info from the document. . .
Let's start with the PICture. For this
Quote: |
+1234 in character format |
the PICture in a COBOL program would be PIC S9(4). Internally, it would be stored as x'F1F2F3C4' - note the "C" sign in the low order digit.
The binary value is 1111 0001 1111 0010 1111 0011 1100 0100'
Keep in mind that both the EBCDIC and ASCII character sets are represented by x'00-FF', but the values for the bit patterns is not the same between platforms. This also leads to a difference in collating sequence - the biggest/easiest example is that the numbers 0-9 are lower in the collating sequence than A-Z on ASCII systems, but 0-9 is higher than A-Z on the mainframe.
There are multiple places on the web where you might download both character sets. |
|
Back to top |
|
|
Vedam
New User
Joined: 24 Apr 2007 Posts: 23 Location: India
|
|
|
|
I was a bit confused when I saw the ASCII characters being shown in the document. Now, I am clear. Thanks a lot for your help. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
You're welcome |
|
Back to top |
|
|
|