Search code examples
binaryfilestext-editor

Is it possible that text editor could contain character values after writing a double value into the file


If you write a double value into a binary file and open that binary file in a text editor. Is it
possible that you might see the string ABCDEFGH in the file ?


Solution

  • Yes, although the value of the double that results in ABCDEFGH will vary between systems.

    Most modern computers use a little endian representation for both integers and IEEE floating point numbers. In this case, the value of the double will be: 1.5839800103804824e+40.

    For systems using big endian integers and big endian IEEE floating point numbers: 2393736.541207228

    On systems that use different endianness for their integers and floating pointer numbers, it doesn't appear to be possible to do this. (ABCDEFGH corresponds to an alias of zero, so you can't necessarily convert the other way)

    And apparently, there are some ARM chips out there that use little endianness overall, but swap the words of their double precision numbers. On such a system, ABCDEFGH could be produced with 710524627902859500000.0.

    Edit: and all of this assumes that your text editor is using an ASCII-compatible text encoding.