Subject Re: [firebird-support] How to store a string in Firebird which includes #0's in it?
Author River~~
Hi Hamish

Thanks for introducing float to this discussion: the varying ways different architectures  store the 'same' float  (like 3.0e8 for example) amplify the point I was making.

A float is stored in binary. 

That is not suggesting that it is stored as the base2 coding of it as an integer.

It is acknowledging that the only way modern digital media store anything as some binary coding scheme. So a float is encoded somehow as binary.

I don't usually say 'encoded' because everything is encoded, even standard integers have a choice of whether and how negatives are stored. And the choice of which way round to code a zero or one into the physical medium is itself a coding standard.

I am suggesting that it is just as valid to talk about it being stored in hex as binary: both impose a numerical representation that is not usually directly relevant to what is being remembered.  

Hex is a more compact form of binary because each hex digit represents four bits, and I know what those bits are just by looking. 

So my habit, my gut feeling, my intuition, is that any binary pattern can just as well be written as hex. It is just notation.

If you are happy to know that the postultimate byte of a C string is a byte with all its bits zero then it is valid to say that as binary b00000000 or as hex x00.

Which is easier to type? to understand?

I am going to apply that intuition to float, inspired by Hamish's point. Some readers will want to leave at this point...

A Float is encoded differently to an Integer - Some range of bits is understood to be mantissa and some others the exponent. True. 

But that fact is not stored in memory along with those bits. The bits of the mantissa and exponent are stored as naked bits leaving the hardware or software to interpret them. 

((students seem to find the expression "naked bits" a memorable mnemonic))

When you define a variable type in a language, or a field type in a database system, you are defining two things.

Firstly how the bits are processed - are they interpreted as a base 2 integer, as a BCD integer, as a float, etc, or even as machine code. If it is a float, is the mantissa defined to base 2 or base 16? (Both have existed in my programming career). 

Secondly presentation: how they are displayed on output.

The point I was originally making was that any bit pattern can be displayed in hex, as well as the obvious format for that type. That is why hex is used for core dumps. If hex couldn't represent everything they'd use something else.

An interesting example of this is the EICAR string which is a string of printable characters that when coded in 8bit ascii and loaded into an x86 actually runs as valid machine code! 

Is the EICAR code a character string or instruction code? Or hex? 

I am saying it is any of these, all of them at once.

Coming back to Float.

Ask me how NEGINF (float  negative infinity) was stored in a CDC7600 and at one time I would have given you the answer in hex.

The hex value will not (of course) be intended to mean it's an integer with that base16 value. NEGINF is by definition a lot further from zero than any storable integer. But it still has a hex value.

If asked how some specific float value like 3.0e8 is stored in two different architectures and the most manageable way to answer is in hex.

So in my opinion it is never wrong to say some octet is hex 00, just as it is never wrong to say it is binary 00000000. 

So to go back to the original point I disputed, I personally intend to go on referring to the byte terminating a C string as being x00 not as the more pedantically correct chr(0). 

I respect the counter argument that I might mislead people to code the ascii characters for the hex digits. 

I can see the sense of that advice but it doesn't persuade me to change the habits of a professional lifetime.

R~~

On Wed, 8 Aug 2018, 00:35 Hamish Moffatt hamish@... [firebird-support], <firebird-support@yahoogroups.com> wrote:
 

On 04/08/18 23:06, 'River~~' river14april@... [firebird-support] wrote:
 

To say an octet is in hex is no more wrong than to say some number is stored as a float. It's all just a bucket of bits. Hex or float or Integer are always presentation 

Float or integer is definitely not a matter of presentation but of encoding. Floats are stored encoded as sign, mantissa, and exponent.
https://softwareengineering.stackexchange.com/questions/215065/can-anyone-explain-representation-of-float-in-memory

Integer versus fixed point is a matter of presentation perhaps, but not floating point.

Hamish

hi