Tuesday, June 25, 2024
HomeMatlabIBM Hexadecimal Floating Level » Cleve’s Nook: Cleve Moler on Arithmetic and...

IBM Hexadecimal Floating Level » Cleve’s Nook: Cleve Moler on Arithmetic and Computing

Our technical help group not too long ago acquired a request for a device that may convert IBM System/360 hexadecimal floating level numbers to the IEEE-754 format. I’m most likely the one one left at MathWorks that really used IBM mainframe computer systems. I believed we had seen the final of hexadecimal arithmetic years in the past. However, it seems that the hexadecimal floating level format is alive and properly.


IBM System/360

The System/360 is a household of mainframe computer systems that IBM launched in 1965 and that dominated the pc business till PCs got here alongside twenty years later. They vary in dimension from desk-sized to programs that fill a big room.

Right here is a photograph of a mid-sized mannequin.

System/360, Mannequin 60. Picture from Ken Shirrif’s weblog, IBM 360/System Abstract.

The System/360 structure is byte-oriented, so it could actually deal with enterprise knowledge processing in addition to scientific and engineering computation. This results in base-16, relatively than base-2 or base-10, floating level arithmetic.

* Binary      f*2^e    1/2<=f<1
* Decimal     f*10^e   1/10<=f<1
* Hexadecimal f*16^e   1/16<=f<1


Floating level codecs performed an vital function in technical computing within the early days. This desk from FMM lists codecs that have been in use within the Nineteen Seventies, earlier than IEEE-754 was launched in 1985.


The System/360 hexadecimal format is utilized in many industries for the preservation of knowledge information.

CREWES. Educating exploration seismology. Complete MATLAB toolbox to be used with the textbook “Numerical Strategies of Exploration Seismology with algorithms in Matlab” by Gary F. Margrave, a geoscience professor on the College of Calgary.

Library of Congress. Authorities.

NASA. Astronautics.

SAS. Statistics and enterprise analytics. SAS wrapers for C.

Enthought. Python wrappers for C.


Hex_ieee. I’ve two twenty-line MATLAB capabilities, ieee2ibm and ibm2ieee, that convert IEEE-754 floating level to and from IBM hexadecimal format.

Three statements in the course of ieee2ibm are the important thing to the complete operation. The primary assertion is

    [~,e] = log2(x)

With two output arguments, log2 returns the mantissa and exponent of an IEEE-754 floating level quantity. The mantissa isn’t wanted right here.

The second key assertion

    e = ceil(e/4)

makes e divisible by 4. This turns e into the suitable hexadecimal exponent in order that the third assertion

    f = x.*16.^(-e)

can produce the hexadecimal mantissa.


perform z = ieee2ibm(x)
   Convert IEEE-754 to IBM System 360 hexadecimal.
   z = ieee2ibm(x)
      Enter x, actual column vector.
      Output z, size(x)-by-16 char.
   Instance: ieee2ibm(-118.625) = 'C276A00000000000'.
      s = signal(x);                      % -1, 0, or 1
      x = abs(x);
      x(x < 16^(-65)) = 0;              % Underflow
      x(x >= 16^63) = (1-eps/2)*16^63;  % Overflow
      [~,e] = log2(x);                  % base 2 exponent
      e = ceil(e/4)                     % base 16 exponent
      f = x.*16.^(-e);                  % base 16 mantissa
      E = uint64((e+64)*2^56);          % Assemb1e output
      F = uint64(f*2^56);
      S = uint64((1-s)*2^62);           % 1 or 0
      z = dec2hex(S + E + F);           % z = 'ZZFFFFFFFFFFFFFF'


perform x = ibm2ieee(z)
   Convert IBM System 360 hexadecimal to IEEE-754.
   x = ibm2ieee(z)
      Enter z, n-by-16 char.
      Output x, n-by-1 double.
   Instance: ibm2ieee('C276A00000000000') = -118.625.
      E = hex2dec(z(:,1:2));           % Disassemble enter
      F1 = hex2dec(z(:,3:8));          % < 16^6
      F2 = hex2dec(z(:,9:finish));        % < 16^8
      s = signal(128-E);                 % -1 or 1
      e = E-(s>0)*64-(s<0)*192;        % base 16 exponent
      f = F1/16^6 + F2/16^14;          % base 16 mantissa
      x = s.*f.*16.^e;


Underflow. Something < 16^(-65) is simply too small and is flushed to zero. There are not any denormals.

Overflow. Something >= 16^63 is simply too giant. There isn’t a inf or NaN.

* 1.0           4110000000000000
* 0.1           401999999999999A
* -pi           C13243F6A8885A30
* 5.3976e-79    0010000000000000
* 7.2370e+75    7FFFFFFFFFFFFFF8


S/360 hexadecimal has 7 exponent bits, whereas IEEE-754 has 11. Consequently, hexadecimal has a a lot smaller vary, 5.4e-79 to 7.2e+75 versus 2.2e-308 to 1.8e+308.

The bottom-16 normalization implies that hexadecimal successfully has between 53 and 56 mantissa bits. Counting the hidden bit, IEEE-754 additionally has 53. So, the accuracy of the 2 is just about the identical.

Software program

My capabilities ieee2ibm and ieee2ibm described above, modified to deal with each single and double, plus hex_test, which does what its title implies, can be found at Hex_ieee.

Homework: What occurs?

okay = 0;
for ok = 1:10
     x = single(ok/10);
     okay(ok) = hex_test(x);

Revealed with MATLAB® R2024a



Please enter your comment!
Please enter your name here

Most Popular

Recent Comments