COMP-1 and COMP-2 Internal storage parsing

Source: Internet
Author: User

in the work of the mainframe, many of the time we do is read dump, and then reverse the Vsam/qsam data set to find improper records, especially when the data set is very large, accurate positioning a record is very inconvenient ... the use of floating-point reverse lookup here is a shortcut (e.g. we see X 'c411570a ' in dump, If we can quickly figure out -4439.039 , and then search for -4439.039 in the dataset, I believe it's easy to lock the target record you want, and below we analyze how the mainframe stores the floating-point numbers and how quickly we can figure out their corresponding decimal data.

we know in COBOL :

COMP-1 is used to define a single-precision floating-point number, accounted for four bytes (corresponds to the e definition in hlasm/mainframe assembler)

COMP-2 is used to define a double-precision floating-point number, accounted for eight bytes (corresponds to the D definition in hlasm/mainframe assembler )

For specific internal storage see:

The parsing is as follows:

The No. 0 bit (the leftmost bit is the No. 0 bit, and so on) is the sign bit,0 is positive, and 1 is negative .
第1-7位 is the number of digits, the initial value is x ' +', if the decimal point is shifted to 1 bits, then the initial value is added 1, X '"; if you move 1 bits to the right, then minus 1. , for X '3F '.
The 8-31/8-63 bit is the trailing digit, or it can be said to be a combination bit (8-31 is for comp-1,8-63 for COMP-2).

1. The host is a pure decimal and very bit not 0 of the form of data storage

Address Memory data constant name constant Value

000064 427b74bc A DC E ' 123.456 '
000068 427b0000B DC E ' 123 '
00006C 4074bc6aC DC E '. 456 '
000070 C27B74BCX DC E ' -123.456 '
000074 00000000                          
000078 427b74bc6a7ef9dbY DC D ' 123.456 '

A,B are all defined as constants, and a can be considered as B + C and
  Span style= "Color:black" >b:   123 = X ' 7b ' should be changed to 0.7B * 16^2 as required, because the exponent is + 2, so the bit bit of the exponent becomes X ' +x ' 2 ' =x ' 42 ', i.e. the memory is 427b0000
  c: 0.456= x ' 0.74bc6a7ef9db ' =0.74bc6a7ef9db   * 16^0 (because C up to four bytes, the back of the storage can not auto-discard, this and we often say the novel point after the exact number of meaning is the same)

before the computer is added and reduced, the first thing to do is to ensure that the exponent is consistent and then the decimal point is aligned. To understand this, we can refer to the following decimal, such as 100*10^1+ 0.008*10^2, the general algorithm is: 100*10^1+ 0.008*10^2 = 1000 + 0.8 = 1000.8

in fact, the implicit constraint here is to first turn the exponent into the same, then the decimal point (just here the exponent part is 10^0).

In fact, the computer also did this:
1. Turn the first two digits (digits) into the same: 4074bc6a, 41074bc6 420074BC
2. then the calculation of c+b=a : 420074bc+ 427b0000 = 427B74BC

And then we see that x and y,x are the opposite of a, y and a are just different in precision.
X is a negative number, so its memory first bit bit is 1.
Y is defined as a double-precision floating-point number Type (COMP-2), and you can see that the memory data of a and Y are just different in accuracy.

2. Analyze an in-memory data, such as: c211570a

Span style= "Color:black" >
1. because the first bit is 1, it is a negative number,
2. Since the digits are x ' 42 ' Is the integer part, 570A is the fractional part
3. The integer part 11 becomes the decimal number
4. Fractional part 0.570A becomes decimal 0.339996337890625, approximately equals 0.34

(here is a link to Baidu, decimal/ 16 conversion Tool:http://www.baidu.com/s?tn=baiduhome_pg&ie=utf-8&bs=Fraction &f=8&rsv_bp=1&rsv_spt=1&wd=01+%e5%8d%81%e5%85%ad%e8%bf%9b%e5%88%b6%e8%a1%a8%e7%a4%ba&rsv_ sug3=9&rsv_sug=0&rsv_sug1=9&rsv_sug4=688&inputt=10402)
5. that is, this number is -17.34 .


3. How to quickly reverse the introduction of the decimal we want from a hexadecimal data


1 ) fast reverse (decimal calculated from hexadecimal):
c211570a = Span style= "Font-family:courier New" > (-X ' 11570A '/16^6) *16^2 
         =-X ' 11570A '/16^4 
         = -1136394/ 65536 
         =- 17.34

c411570a = (-X ' 11570A '/16^6) * 16^4
=-X ' 11570A '/16^2
= -1136394/256
=-4439.039

2 ) Fast Forward (16 binary from decimal):

17.34 = 0.1734 * 10^2
= 1734/10^2
= X ' 6c6 '/x ' 64 '
= (x ' 6c60000 '/x ') * (1/x ' 10000 ')
= 11570a* (1/x ' 10000 ')

Why first let dividend X ' 10000 ', because the laptop comes with the computer in the 16 binary division, only show the whole part. In fact, the computer is also unable to represent the fractional part of the 16, because we usually say that the decimal point, are for the decimal, Who has seen the decimal point of 16 binary?

so the memory is then reduced by the X ' 10000 ' times: X ' 4211570A ' (if not zoomed in X ' 4611570A ')

The overall idea of the above method is to turn the divisor and dividend into integers, and then perform the operation.

If you have any questions, please contact: QQ349106216

COMP-1 and COMP-2 Internal storage parsing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.