- By
**Mercy** - Follow User

- 740 Views
- Uploaded on

Download Presentation
## PowerPoint Slideshow about 'Internal Representation of Data in COBOL Data Types' - Mercy

**An Image/Link below is provided (as is) to download presentation**

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript

Audience

- This document explains how data is internally represented in COBOL data types on IBM Mainframes.
- Discussion on data types requires knowledge of binary data representation and binary arithmetic. Hence, this document introduces binary data representation and binary arithmetic as well.

Topics

- Binary & Hexadecimal Representation
- Binary Arithmetic
- Cobol Data Types & their Internal Representation
- ASCII to EBCDIC Conversion Chart
- Note: If you are comfortable with Binary arithmetic, you are advised to move on to Cobol Data Types & their Internal Representation

Decimal Number System

- We use decimal number system in our daily life.
- Decimal number system has ten symbols. The symbols are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9.
- These ten symbols are used to represent all numbers.
- If a number is represented by 456, it’s value is 4*102 + 5*101 + 6*100.

Binary Number System

- In Binary number system we use only two symbols, 0 and 1. These two symbols are used to represent all numbers.
- If a number is represented by 10, it’s value is 1*21 + 0*20 = 2.
- Similarly 101 = 1*210 + 0*21 + 1*20 = 1*22 + 0*21 + 1*20 = 4 + 0 + 1 = 5.

Hexadecimal Number System

- In hexadecimal number system we use sixteen different symbols, 0 - 9 & A,B,C,D,E,F.
- Here A=10,B=11,C=12, D=13, E=14, & F = 15.
- If a number is represented by 456 in hexadecimal number system, it’s value is – 4*162 + 5*161 + 6*160.

Number Systems -1

- To represent a value 15, we need -
- Two digits in decimal system. ( 1 & 5)
- One digit in hexadecimal system. (F)
- Four digits in binary system. (1111)

Number Systems -2

- In decimal system using 2 digits we can represent 102 different numbers. (00 … 99, a total of 100)
- Using ‘n’ digits in decimal system, we can represent, 10n different numbers.

Number Systems -3

- In binary number system, using two digits we can represent four numbers – 00, 01, 10, 11 (22 numbers).
- With ‘n’ digits we can represent - 2n numbers in binary number system.
- Using eight digits we can represent 28 (i.e, 256), different numbers.

Conversion from Binary to Hexadecimal Number System

- To convert from one number system to another, we normally convert –
- From Number System 1 to Decimal System
- Then from Decimal System to Number System 2
- However, there is a direct mapping between binary number system and hexadecimal number system.
- Hence it is very easy to convert from binary to hexadecimal and hexadecimal to binary system.

Conversion from Binary to Hexadecimal Number System -2

- A group of four binary digits are clubbed into a single Hexadecimal digit. (or) a hexadecimal digit can be converted to a set of four binary digits.
- The conversion is -

0000 binary = 0 hex; 0001 binary = 1 hex

0010 binary = 2 hex; 0011 binary = 3 hex

0100 binary = 4 hex; 0101 binary = 5 hex

0110 binary = 6 hex; 0111 binary = 7 hex

etc

Conversion from Binary to Hexadecimal Number System -3

- Let’s take a binary number 11000010.
- It’s decimal value is –

1*27+1*26+1*21 = 128 + 64 + 2 = 194

- Applying the conversion –

=1100 0010 binary = C2 hex

- Decimal value of C2 hex -

= C*161 + 2*160 = 12*16 + 2*1= 192 + 2 = 194

Some Terminology

- In computer systems, binary digits 0 and 1 are used to represent data.
- in a computer system, a memory location storing a binary digit is known as a – ‘bit’.
- Hence, in general a binary digit is also called as a bit.

Some Terminology -2

- Bit is a very small unit.
- In general data storage locations are specified in terms of ‘Bytes’, where 8 bits is One byte.
- Similarly -
- 2 Bytes is one ‘Half Word’
- 4 Bytes is one ‘Word’
- 8 Bytes is one ‘Double Word’
- 4 BITS is one ‘Nibble’ (Rarely Used)

Binary Number System -5

- 210 Bytes is 1 KB (One Kilo Byte)
- It is 1024 bytes actually. However, we call this as one Kilo bytes.
- 220 Bytes is 1 MB (One Mega Byte)
- Same as 210 KB
- 230 Bytes is 1 GB (One Giga Byte)
- Same as 210 MB
- 240 Bytes is one Tera-byte
- 250 Bytes is one Peta-byte
- 260 Bytes is one Exa-byte

Representation

- Now we have three different number systems – decimal, binary & hexadecimal.
- ‘100’ is a valid number in all three number systems. However, it’s value is different in each system. How do we decide, to which number system it belongs to?
- To make things clear we use ‘0x’ as a prefix to hexadecimal numbers, and ‘0b’ as a prefix to binary numbers and none if it is a decimal number.

Representation -2

- Hence -
- 0x 100 is a hexadecimal number (value 256)
- 0b 100 is a binary number (value 4)
- 100 is a decimal number (value 100)

Summary of Number Systems

- If a number systems base is ‘b’; then using ‘n’ digits, we can represent ‘bn’ different values.
- Direct conversion from binary to hexadecimal and hexadecimal to binary is very easy.

Binary Arithmetic

- All mathematical operations in binary system are similar to the ones done in decimal number system. We can draw parallels and use them.
- Mathematical operations on hexadecimal numbers are carried out by –
- Converting hexadecimal numbers to binary numbers.
- Carry out arithmetic operation on binary numbers.
- Convert the binary numbers back to hexadecimal numbers.

Addition -1

- 7 + 8 = 15 (Decimal System)
- In the above, 5 is the sum and 1 is a carry that goes to the higher digit.
- Similarly, in binary system –
- 0 + 0 = 0 , no carry
- 0 + 1 = 1 , no carry
- 1 + 1 = 0 , 1 carry

Addition -2

- Addition 67 + 98 (decimal) is done by
- Adding 7 & 8 – result is 5 with a carry of 1
- Now, 6 & 9 are added along with the carry, resulting in 6, and carry of 1
- Hence, the result is 165.

Addition -3

- Similarly, adding 0b10 to 0b11 is done by
- Adding 0 & 1 – result is 1, no carry
- Now, 1 & 1 are added, resulting in result of 0 and carry of 1
- Hence, the result is 0b101.
- Similarly, adding 0b11 to 0b11 is done by
- Adding 1 & 1 – result is 0, carry 1
- Now, 1 & 1 are added, along with the carry, resulting in result of 1 and carry of 1
- Hence, the result is 0b110.

Subtraction -1

- Subtraction in decimal system can be carried out by a method called tens complement method.
- Tens complement of 4 is 6. (sum is ten)
- Tens complement of any number can be obtained by nines complement and adding one to it.
- Nines complement of 4 is 5. (sum is nine)
- Hence tens complement of 4 is 5+1 = 6.

Subtraction -2

- Tens complement of a multi-digit number is obtained by –
- Getting nines complement of individual digits
- Adding one to that 9’s complement number
- Hence to get tens complement of 64
- Get nines complement (it is 35)
- Add one to the nines complement (result 36)

Subtraction -3

- To subtract 64 from 86 –
- Get tens complement of 64 (Tens complement is 36)
- Add tens complement to 86.
- Discard the carry generated in the result.
- Hence 86 – 64 is converted into 86 + 36
- The sum is – 122
- Discarding the carry, the result is 22.
- Verification (86 – 64 = 22)

Subtraction -4

- Complement theory can be extended to binary arithmetic also.
- In decimal we use 10’s complement. Here in binary arithmetic, we use 2’s complement.
- 2’s complement of a number is obtained by getting one’s complement and then adding one to it.

Subtraction -5

- One’s complement can be obtained by replacing 0 with 1, and 1 with 0.
- i.e one’s complement of 0b1001 is 0b0110.
- Now, two’s complement of 0b1001 is
- 0110 + 0001 = 0111
- What’s the twos complement of 0b0000?
- One’s complement is – 0b1111
- Two’s complement is – 0b1111 + 0b0001 = 0b1 0000
- Hence the result is 0b0000. (Discard carry generated.)

Subtraction -6

- Assume subtracting 12 from 15. (Decimal)
- The result is 15 – 12 = 03.
- Convert the above numbers to binary.
- They are 0b1100 (12) and 0b1111 (15)
- One’s complement of 0b1100 is 0b0011
- Two’s complement of 0b1100 is 0b0100
- Adding 0b0100 to 0b1111, we get 0b1 0011
- Discarding the carry – the result is 0b0011, which is equivalent to 03.

Subtraction -7

- Two’s complement method is used as –
- It is easy to implement in systems
- We can use addition circuits to do subtraction operation as well.

Positive and Negative Numbers -1

- Till now we discussed about unsigned numbers only.
- Using unsigned numbers, we did addition and subtraction.
- However, we can look at subtraction as addition of a negative number.
- Then, the question is – “How do we represent negative numbers?”

Positive and Negative Numbers -2

- We said that, “We can look at subtraction as addition of a negative number.”
- We also said that, “Adding a two’s complement of a number is same as subtraction of that number.”
- Hence, we can deduce that – “Two’s complement of a number can be seen as a negative number!”

Positive and Negative Numbers -3

- Here are a few four bit numbers, and their two’s complement numbers.

Number Two’s complement

0b0000 = +0 0b0000 = -0 (Same!)

0b0001 = +1 0b1111 = -1

0b0010 = +2 0b1110 = -2

0b0011 = +3 0b1101 = -3

0b0100 = +4 0b1100 = -4

0b0101 = +5 0b1011 = -5

Etc…

Positive and Negative Numbers -4

- If a number 1234 is given, in that 1 is the most significant digit and 4 is the least significant digit.
- Similarly in 0b 1010 –
- 1 is the Most Significant Bit (MSB) &
- 0 is the Least Significant Bit (LSB)

Positive and Negative Numbers -5

- All positive numbers have 0 in MSB
- All negative numbers have 1 in MSB
- 0b1100 is a four bit representation for ‘-4’
- To get eight bit representation of ‘-4’ –
- Take a eight bit representation of ‘4’, and get the corresponding 2’s complement. (or)
- Take the four bit representation and extend the sign.
- i.e. ‘-4’can be represented in eight bit as 0x1111 1100
- Verification.
- 1’s complement of 0b0000 0100 is 0b1111 1011
- Hence, 2’s complement of 0b0000 0100 is 0b1111 1100
- Same as the one obtained by sign extension.

Positive and Negative Numbers -6

- Four digits represent 16 different values, ranging from -8 … 0 … +7.
- Hence four digits are representing values ranging from -23 ... 0 … +(23-1)
- With ‘n’ bits, the range represented can be generalized to -2n-1 ... 0 … +(2n-1-1)

Boolean Operators

- NOT, AND, OR are the most important Boolean operators.
- NOT : NOT 1 = 0 & NOT 0 = 1 (Opposite)
- AND : 0 AND 0=0, 0 AND 1=0,

1 AND 0=0, 1 AND 1=1

(1 only if both are one)

- OR : 0 OR 0=0, 0 OR 1=1,

1 OR 0=1, 1 OR 1=1

(1 only if any one of them is one)

AND Operators

- AND operator is extensively used later in the presentation. Let’s see a bit more about it. Let us represent it by ‘&’.
- 1111 & 1111 = 1111 (F & F = F)
- 1111 & 1101 = 1101 (F & D = D)
- 1111 & 1100 = 1100 (F & C = C)

EBCDIC Character Set

- Before we get down to look at how data is stored in Cobol variables defined in an IBM Mainframe system, it is good to know some thing about the EBCDIC character set that is used to represent the values.
- EBCDIC stands for ‘Extended Binary-Coded Decimal Interchange Code’.

EBCDIC Character Set

- 0x81 to 0x89 represent characters ‘a’ to ‘i’
- 0x91 to 0x99 represent characters ‘j’ to ‘r’
- 0xA2 to 0xA9 represent characters ‘s’ to ‘z’
- 0xC1 to 0xC9 represent characters ‘A’ to ‘I’
- 0xD1 to 0xD9 represent characters ‘J’ to ‘R’
- 0xE2 to 0xE9 represent characters ‘S’ to ‘Z’

EBCDIC Character Set

- 0xF0 to 0xF9 represent characters ‘0’ to ‘9’
- 0x4E represents ‘+’ (Plus symbol)
- 0x60 represents ‘-’ (Minus symbol)
- 0x40 represents ‘ ‘ (SPACE)

EBCDIC Character Set

- If you type a character ‘a’ on your keyboard, internally system stores 0x81.
- Similarly, if you type a character ‘5’ on your keyboard, internally system stores 0xF5.
- These are hexadecimal symbols for the character, in EBCDIC character set.

Data Representation

- Character (Alphabetic or alpha-numeric) data can be represented only in one way. That is, by storing the corresponding EBCDIC characters in the memory locations.
- One character takes one byte in the memory.
- PIC X(nn) & PIC A(nn) use this mechanism to represent and store data.
- However, numeric data can be represented in many ways.

Data Representation

- Numeric data can be classified as Integer & Decimal Data.
- 10, 34, 3456 are integers
- 1.234, 12.34, 1234.56 are decimal numbers
- Both Integer & Decimal data can be represented in many ways.

Integer Data Representation

- One of the ways of representing Integer data is by storing the corresponding EBCDIC characters in memory.
- PIC 9(nn) uses this method to store data.
- In this method -
- One digit takes one memory location
- To store a value 89, 0xF8 F9 is stored in memory. (If 9(2) is the PIC clause)
- To store a value 89, 0xF0 F8 F9 is stored in memory. (If 9(3) is the PIC clause)
- PIC 9(nn) is an unsigned data representation.

Integer Data Representation

- In this format how negative numbers are stored?
- Assume we would like to store a negative number. We may use –
- S9(02)
- S9(02) SIGN TRAILING
- S9(02) SIGN LEADING
- S9(02) SIGN TRAILING SEPARATE
- S9(02) SIGN LEADING SEPARATE
- S9(02) is same as S9(02) SIGN TRAILING, as ‘sign trailing’ is the default.

Integer Data Representation

- Assume we would like to store, ‘89’, which is a positive number. ’89’ is represented by 0xF8F9.
- In S9(02), it is stored as ‘0xF8C9’. (2 bytes). Least Significant Byte 0xF9 is ANDed with 0xCF resulting in 0xF8C9.
- In S9(02) SIGN TRAILING, it is stored as ‘0xF8C9’. (2 bytes)… sign represented in the least significant byte. Least Significant Byte 0xF9 is ANDed with 0xCF resulting in 0xF8C9.
- In S9(02) SIGN LEADING, it is stored as ‘0xC8F9’. (2 bytes)… sign represented in most significant byte. Most Significant Byte 0xF8 is ANDed with 0xCF resulting in 0xC8F9.

Integer Data Representation

- In S9(02) SIGN TRAILING SEPARATE, it is stored as ‘0xF8F94E’. (3 bytes) … sign represented separately. Sign takes additional byte in memory.
- In S9(02) SIGN LEADING SEPARATE, it is stored as ‘0x4EF8F9’. (3 bytes) … sign represented separately. Sign takes additional byte in memory.

Integer Data Representation

- Assume we would like to store, ‘-89’, which is a negative number. ’89’ is represented by 0xF8F9.
- In S9(02), it is stored as ‘0xF8D9’. (2 bytes) Least Significant Byte 0xF9 is ANDed with 0xDF resulting in 0xF8D9.
- In S9(02) SIGN TRAILING, it is stored as ‘0xF8D9’. (2 bytes)… sign represented in the least significant byte. Least Significant Byte 0xF9 is ANDed with 0xDF resulting in 0xF8D9.
- In S9(02) SIGN LEADING, it is stored as ‘0xD8F9’. (2 bytes) … sign represented in most significant byte. Most Least Significant Byte 0xF8 is ANDed with 0xDF resulting in 0xD8F9.

Integer Data Representation

- In S9(02) SIGN TRAILING SEPARATE, it is stored as ‘0xF8F960’. (3 bytes) … sign represented separately. Sign takes additional byte in memory.
- In S9(02) SIGN LEADING SEPARATE, it is stored as ‘0x60F8F9’. (3 bytes) … sign represented separately. Sign takes additional byte in memory.

Integer Data Representation

- In sign trailing representation, data in the ‘Least Significant Byte’ is –
- AND ed with 0xCF for +ve numbers and
- AND ed with 0xDF for -ve numbers.
- In sign leading representation, data in the ‘Most Significant Byte’ is –
- AND ed with 0xCF for +ve numbers and
- AND ed with 0xDF for -ve numbers.
- In sign separate representation, appropriate sign character is either prefixed or suffixed as per the definition.

Integer Data Representation

- Integer data can also be represented by storing the corresponding binary value in the memory.
- COMP variables use this mechanism.
- PIC S9(04) COMP takes two bytes & S9(08) COMP takes four bytes.
- To store 89 in S9(04) COMP
- Binary equivalent of 89 is 0x0059.
- Hence, 0x0059 is stored in the memory.
- 0x00 is stored in the higher address location & 0x59 is stored in the lower address location.
- In a S9(08) COMP variable, the same value 89 is stored as 0x00000059. 0x00 is stored in the highest address location & 0x59 in the lowest address location.

Integer Data Representation

- How -89 (-ve value) is stored in S9(04) COMP?
- Binary equivalent of 89 is 0x0059.
- Two’s complement of 0x0059 is 0xFFA7.
- Hence, -89 is stored as 0xFFA7 in the memory.
- Using S9(04) COMP variable,
- It is also called as Half-word Binary.
- values between, (-215) to (215 -1) can be represented.
- Using S9(08) COMP variable,
- It is also called as Full-word Binary.
- values between, (-231) to (231 -1) can be represented.

Integer Data Representation

- In S9(n) COMP –
- If ‘n’ is between 1 to 4, it takes two bytes in memory.
- If ‘n’ is between 5 to 9, it takes four bytes in memory.
- Compiler option TRUNC influences the way S9(n) variables behave.
- If TRUNC(BIN) is specified, the full range of values -2m-1 to (2m-1 -1) can be stored in the variable, where ‘m’ is the number bits in the memory occupied by the variable.
- If TRUNC(OPT) is specified, the value of ‘n’ determines the range of values that can be accepted by the variable. S9(02) COMP can accept values between -99 to 99 only, though the two bytes occupied by it are capable of storing a much larger value.

Integer Data Representation

- BINARY and ‘COMP-4’ data types are same as COMP.
- ‘COMP-5’ is also similar to COMP. However, it does not depend on the TRUNC option specified by the compiler. It always behaves as if TRUNC(BIN) is specified.

Integer Data Representation

- The third way of representing integer data is by using Binary Coded Decimal (BCD) format.
- This is used by ‘COMP-3’ data types.
- In BCD format, one nibble represents one digit.
- If we look at EBCDIC characters –
- 8 is represented by 0xF8 &
- 9 is represented by 0xF9.
- In BCD format, 89 is represented by 0x089F in 9(04) COMP-3. Here ‘F’ is the sign.
- Least significant nibble stores the sign in COMP-3 data type.

Integer Data Representation

- S9(03) COMP-3 takes two bytes.
- One nibble for each digit and one nibble for sign.
- Can represent -999 to +999.
- 9(03) COMP-3 takes two bytes.
- One nibble for each digit, and one nibble for sign. (Thought sign is never used, it takes a nibble in the storage.)
- Can represent 000 to 999.

Integer Data Representation

- 89 is represented by –
- 0x089F,in 9(03) COMP-3 data type. (Least significant byte is 0xF for unsigned representation.)
- 89 (+ve value) is represented by –
- 0x089C,in S9(03) COMP-3 data type. (Least significant byte of 0x089F is AND ed with 0xFC for signed representation of +ve numbers.)
- ‘-89’ (-ve value) is represented by –
- 0x089D,in S9(03) COMP-3 data type. (Least significant byte of 0x089F is AND ed with 0xFD for signed representation of -ve numbers.)

Decimal Data Representation

- Decimal data representation can be used to represent data containing fractions.
- Different ways available for us to represent decimal data are –
- PIC 9(nn)v9(mm)
- PIC S9(nn)v9(mm)
- PIC 9(nn)v9(mm) COMP-3
- PIC S9(nn)v9(mm) COMP-3
- COMP-1
- COMP-2

Decimal Data Representation

- PIC 9(03)v9(02) –
- Takes five bytes in the memory
- A virtual decimal point is assumed after three digits, in the place of ‘v’
- Can store values between 0 to 999.99
- If 123.45 is to be stored in this variable, it stores 0x F1 F2 F3 F4 F5.
- Sign stored in least significant byte (LSB). LSB AND ed with 0xFF for unsigned number.

Decimal Data Representation

- PIC S9(03)v9(02) –
- Takes five bytes in the memory
- Can store values between -999.99 to +999.99
- If 123.45 is to be stored in this variable, it stores 0x F1 F2 F3 F4 C5. Sign stored in least significant byte (LSB). LSB AND ed with 0xCF for +ve numbers.
- If ‘-123.45’ is to be stored in this variable, it stores 0x F1 F2 F3 F4 D5. Sign stored in least significant byte (LSB). LSB AND ed with 0xDF for -ve numbers.
- PIC S9(03)v9(02) SIGN TRAILING, is same as PIC S9(03)v9(02)

Decimal Data Representation

- PIC S9(03)v9(02) SIGN LEADING –
- Takes five bytes in the memory
- Can store values between -999.99 to +999.99
- If 123.45 is to be stored in this variable, it stores 0x C1 F2 F3 F4 F5. Sign stored in most significant byte (MSB). MSB AND ed with 0xCF for +ve numbers.
- If ‘-123.45’ is to be stored in this variable, it stores 0x D1 F2 F3 F4 F5. Sign stored in most significant byte (MSB). MSB AND ed with 0xDF for -ve numbers.

Decimal Data Representation

- PIC S9(03)v9(02) SIGN LEADING SEPARATE –
- Takes six bytes in the memory
- Can store values between -999.99 to +999.99
- If 123.45 is to be stored in this variable, it stores 0x 4E F1 F2 F3 F4 F5. Sign stored in most significant byte (MSB).
- If ‘-123.45’ is to be stored in this variable, it stores 0x 60 F1 F2 F3 F4 F5. Sign stored in most significant byte (MSB).

Decimal Data Representation

- PIC S9(03)v9(02) SIGN TRAILING SEPARATE –
- Takes six bytes in the memory
- Can store values between -999.99 to +999.99
- If 123.45 is to be stored in this variable, it stores 0x F1 F2 F3 F4 F5 4E. Sign stored in least significant byte (LSB).
- If ‘-123.45’ is to be stored in this variable, it stores 0x F1 F2 F3 F4 F5 60. Sign stored in least significant byte (LSB).

Decimal Data Representation

- PIC 9(03)v9(02) COMP-3 –
- Takes three bytes in the memory
- Can store values between 0 to +999.99
- If 123.45 is to be stored in this variable, it stores 0x 12 34 5F. Sign stored in least significant byte (LSB). LSB AND ed with 0xFF for unsigned numbers.

Decimal Data Representation

- PIC S9(03)v9(02) COMP-3 –
- Takes three bytes in the memory
- Can store values between -999.99 to +999.99
- If 123.45 is to be stored in this variable, it stores 0x 12 34 5C. Sign stored in least significant byte (LSB). LSB AND ed with 0xFC for signed +ve numbers.
- If ‘-123.45’ is to be stored in this variable, it stores 0x 12 34 5D. Sign stored in least significant byte (LSB). LSB AND ed with 0xFD for signed -ve numbers.

Decimal Data Representation

- PIC COMP-1.
- This takes four bytes in memory
- Represents data in floating point notation
- Number 1.234 can be represented as
- +0.1234 x 101
- In the above
- + is the sign of the number
- 1234 is the mantissa
- 1 in 101 is the exponent

Decimal Data Representation

- COMP-1 takes four bytes. In the four bytes -
- MSB represents Sign. ‘0’ represents positive number and ‘1’ represents a negative number
- The next seven bits represent exponent in ‘Excess-64’ format. i.e. if the exponent is 65, it indicates the actual exponent is 65-64=01. (Note that, the exponent here is not decimal exponent. It is a hexadecimal exponent.)
- Remaining 24 bits represent Mantissa.

100 0011

0100 1101 0010 0000 0000 0000

Value is 67. Which means exponent is +3.

+ve Sign

Mantissa 0x 4D 20 00

Decimal Data Representation- Let’s take 1234. Internally it is represented as 0x 43 4D 20 00 in a COMP-1 variable.
- When represented in binary form, it is –

Decimal Data Representation

- Mantissa always contains a decimal point at the beginning.
- Since the exponent is ‘+3’, move the decimal point right by three places in the mantissa. Hence the number becomes - 0x 4D2.000, in which 0x 4D2 is the integer part and 0x 000 is the decimal part.
- Decimal equivalent of 0x4D2 is –
- 4*162 + D*161 + 2*160 = 1234.

100 0001

0001 0011 1011 1110 0111 0111

Value is 65. Which means exponent is +1.

-ve Sign

Mantissa 0x 13 BE 77

Decimal Data Representation- Let’s take ‘-1.234’. Internally it is represented as 0x C1 13 BE 77 in a COMP-1 variable.
- When represented in binary form, it is –

Decimal Data Representation

- Since the exponent is ‘+1’, move the decimal point right by one place in the mantissa. Hence the number becomes - 0x1.3BE77, in which –
- 0x 1 is the integer part (this is equal to 1)
- 0x 3BE77 is the decimal part. Decimal equivalent of 0x 3BE77 = 3/161 + B/162 + E/163 + 7/164 + 7/165 =0.23400020599….
- Hence -1.234 is stored as ‘1. 23400020599…’. It means, some precision is lost in the data stored.

Decimal Data Representation

- PIC COMP-2.
- This takes eight bytes in memory
- Represents data in floating point notation
- Data stored is similar to COMP-1 data type except that, mantissa takes seven bytes instead of three bytes.

Synchronized

- SYNC also can be used instead of Synchronized verb
- Introduces ‘slack’ (unused) bytes if necessary, other wise ignored.
- Need to be careful while calculating the length of the group variable, or the memory occupied by the working storage section.

Synchronized

- SYNC has effect only on BINARY, COMP, COMP-1, COMP-2, COMP-4, COMP-5 type variables. If SYNC is specified on any other picture clause, it will be considered as a comment.
- If SYNC is specified, picture clauses, occupying-
- Two bytes will be aligned on half word boundaries
- Four bytes will be aligned on word boundaries
- Eight bytes will be aligned on double word boundaries

Synchronized

- If specified for an elementary item (which is not a group item), it aligns the elementary item as required, by introducing slack bytes.
- If specified for a group item, it aligns all the subordinate elementary item as required, by introducing slack bytes, in that group.

Synchronized

- 01 XYZ.

05 VAR1 PIC X(03).

05 VAR2 PIC S9(04) COMP.

- The above group item occupies five bytes.

Synchronized

- 01 XYZ.

05 VAR1 PIC X(03).

05 VAR2 PIC S9(04) COMP SYNC.

- The above group item occupies six bytes.
- VAR1 takes three bytes.
- One slack byte is introduced after VAR1 to ensure that VAR2 is on a word boundary.
- VAR2 takes two bytes.

Synchronized

- 01 XYZ.

05 VAR1 PIC X(03).

05 VAR2 COMP-2 SYNC.

- The above group item occupies sixteen bytes.
- VAR1 takes three bytes.
- Five slack bytes are introduced after VAR1 to ensure that VAR2 is on a double word boundary.
- VAR2 takes eight bytes.

Download Presentation

Connecting to Server..