Who faced such things as converting float values ​​to IBM Floating 32bit and back? I solve this question in Java , realizing that you need to build on concepts like mantissa, sign, exponent (judging from an article in the Wiki: IBM Floating 32bit Architecture) you get this code to find the values ​​listed above:

public class Main { public static void main(String[] args) { float d = -157.1817f; String binaryBits = Integer.toBinaryString(Float.floatToIntBits(d)); char[] arrayCharact = new char[binaryBits.length()]; arrayCharact = binaryBits.toCharArray(); StringBuilder sign = new StringBuilder(); sign.append(arrayCharact[0]); StringBuilder exponent = new StringBuilder(); for (int k=1; k<7; k++) exponent.append(arrayCharact[k]); StringBuilder mantissa = new StringBuilder(); for (int k=7; k<31; k++) mantissa.append(arrayCharact[k]); System.out.println(sign + "\n" + exponent + "\n" + mantissa); } 

}

What to do next? What to do with these variables? how correct is the approach? and whether I reason correctly, what is the translation of float in IBM Floating 32bit?

PS is not a programmer by education, but Pts will be useful for writing a disser. thank you

  • @bersano, what do you do with these variables? This is a question for you. You are just typing them now, see the toes and ones. Maybe enough? A little on the case. A cycle for getting * a single ** (!!!) sign bit - * this is awesome ! Otherwise (if you really need exponent and mantissa as character strings), why not? At first glance, the image in zeros and edinichka correct. “If sign, exponent and mantissa were to be used as integers in the future, then I would not convert to strings at all, but would pull apart the result of calling Float.floatToIntBits (d) with shifts. - avp
  • Thanks, I’ll explain a little bit to print the lines to check the solution (on the same Wiki link, there is an analysis of how these variables are selected with a different number, but I did not find the final outcome). Yes, with a cycle of 1 line, this is too tricky, I will correct :) You can transfer from lines to numbers or initially receive them in numbers using shifts, you can rewrite a piece of code, but this does not answer any of the questions asked. - bersano
  • Well, uchonye went - another dissertation a la Shamkhalov & Co.? - Barmaley
  • @bersano, something, it seems, I did not fully understand your questions. Specify, do you want to transfer Float from IEEE 754 (Float.floatToIntBits () representation in it) to IBM? Generally, pochtche formulate a question. ("What to do next? What to do with these variables?" - these are questions for you). Now, as far as I understand, you are typing a bit representation in IEEE (and how much it coincides with IBM it is necessary to study). By the way, what about the dissert? - avp
  • @avp yes, that's right, I want to translate from IEEE754 to IBM Floating 32bit and back, I would like to understand how to translate. dissertation on seismic data conversion. SEG-Y format is used, in which just IBM Floating 32bit is used. - bersano

1 answer 1

A long time ago, 100 years ago I solved a similar problem, but on C. There was an array of binary data generated by the IBM System / 360, which had to be read and converted from IBM encoding to standard IEEE encoding. I did something like this:

  1. Read bits IBM
  2. Parsim bits, raskuruchivaem to the state sign / mantissa / exponent
  3. Write bits in IEEE double format
  4. Casting a double

Over the years, the source is clear the stump is no longer preserved. Simple googling gives a link to the source code in C # I suppose that converting the code from C # to Java is not difficult (does it need it?)

Update: Sketched a quick parsing of IEEE float bits:

  float d = -157.1817f; int bits=Float.floatToRawIntBits(d); int sign = ((bits >> 31) == 0) ? 1 : -1; //знак на 31-м бите int exp = ((bits >> 23) & 0xff); //экспонента с 30 по 23 биты int mantissa = (exp == 0) ? (bits & 0x7fffff) << 1 : (bits & 0x7fffff) | 0x800000; //мантисса System.out.println("sign="+sign+", exp="+exp+", mantissa="+mantissa); //проверка double check=sign*mantissa*Math.pow(2.0, exp-150); System.out.println(check); 
  • Similarly, I found (except for the descriptions in Vika) the question of conversion and the answer to C - avp
  • @Barmaley, only IMHO from exp is necessary 127, but not 150 to take away. - avp
  • @Barmaley @avp thanks, sent in the right direction, I will go on puffing on this matter further :) - bersano
  • @avp is not, in Java, as is known, int / long is signed, so when converting a mantissa, a shift of 23 occurs, which is compensated by the exponent 23 + 127 = 150 - Barmaley
  • Yes, you are right - 150. - avp