Chapter Contents |
Previous |
Next |
HEX |
Width range: | 1- 16 |
Default width: | 8 |
Alignment: | left |
CMS specifics: | IBM floating-point format |
Syntax | |
Details | |
See Also |
Syntax |
HEXw. |
Details |
The HEX format converts real binary (floating-point) numbers to hexadecimal representation. Each hexadecimal digit that is written in the EBCDIC code uses one byte per digit. For example, the floating-point number 1.0 has the hexadecimal value 'F1'x (EBCDIC 1) using the HEX1. format.
The w value of the HEX format determines the width of the value and whether the number is written as a floating-point number or an integer. When you specify a width value of 1 through 15, the real binary numbers are truncated to fixed-point integers before being written to hexadecimal values. However, when you specify 16 for the width, the floating-point value is written and the numbers are not truncated. For example, if the value of Y is 31.5, and you use the following PUT statement to write it to the SAS log, the following hexadecimal value is written in EBCDIC code:
put y hex16.; 421F800000000000 ('F4F2F1C6F8F0F0F0F0F0F0F0F0F0F0F0'x)
The result shows the hexadecimal value for the CMS floating-point representation of 31.5. The value of a floating-point number is as follows: the first bit of this number is the sign bit and the next seven bits are the characteristic, or exponent. Since the sign bit is 0, the number is positive. To calculate the exponent from the characteristic, you must subtract hexadecimal 40 from the number. Subtracting '40'x from '42'x gives a difference of '02'x. Thus, the exponent is 216. The last part of the floating-point number, bits 8 through 63, represents the fraction. Since the exponent is 216 , the radix point is moved two places to the right, giving a value of '1F.8'x, which is the hexadecimal equivalent of decimal 31.5.
If you set the variable Y equal to -31.5, you get the following result with a width of 16 specified:
C21F800000000000 ('C3F2F1C6F8F0F0F0'x)
The only difference between this example and the first example is the changing of the first digit from '4'x to 'C'x. This occurs because the sign bit has been changed from 0 to 1 if you set the variable Y equal to -31.5.
However, if you change the format to HEX15. in the first example, the result writes the following hexadecimal value in EBCDIC code:
'00000000000001F'x ('F0F0F0F0F0F0F1C6'x)
This example illustrates the result when a width value of less than 16 is specified. Here, the SAS System first converts 31.5 to an integer by truncating the number to 31. The result is then printed in the specified number of hexadecimal digits.
With a width of less than 16, a negative floating-point number is first truncated to an integer and then printed in twos complement form. Therefore, when the format HEX15. is specified for Y=-31.5, the result is as follows:
FFFFFFFFFFFFFE1 ('C6C6C6C6C6C6C5F1'x)
See Also |
Chapter Contents |
Previous |
Next |
Top of Page |
Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.