### how to read float bytes from Memory?

Posted:

**07 May 2017, 01:00**I am wondering if there is a way to read float bytes from memory directly and put them into an array

I am building some converters for Byte, Nibbles, and Binary for Mini-Framework.

I can work out bytes for any integer type and have also constructed a class to handle UInt64. This is possible as I also built classes for BigInt.

So I have a class for Int16, UInt16, Int32, UInt32, Int64, UInt64, Float and BigInt.

I am working on conversions and parsing but am not sure how to get the bytes for a float value. I know that a float should be 64 bits in AutoHotkey but I am unable to get the bytes to convert to and from the conversion I need.

I thought perhaps NumGet but show more then 64 bytes.
Even when I try offseting by 2 bytes and using UShort I am not get correct value.

Any Ideas?

I can Get integer value for float using the following methods
For Positive float values i get a positive integer from _Int64ToFloat() and this seems to work as I can convert the Positive integer value to bytes.

However when the float value is negative _Int64ToFloat() returns a negative value and conversion no longer works. I am guessing the bits are being wrap somehow.

For any other integer my conversion work just fine so I know its not my conversion of the integer.

I am building some converters for Byte, Nibbles, and Binary for Mini-Framework.

I can work out bytes for any integer type and have also constructed a class to handle UInt64. This is possible as I also built classes for BigInt.

So I have a class for Int16, UInt16, Int32, UInt32, Int64, UInt64, Float and BigInt.

I am working on conversions and parsing but am not sure how to get the bytes for a float value. I know that a float should be 64 bits in AutoHotkey but I am unable to get the bytes to convert to and from the conversion I need.

I thought perhaps NumGet but show more then 64 bytes.

Code: Select all

```
val := 1.12345675646456456456
MsgBox % VarSetCapacity(val) ; returns 126
```

Any Ideas?

I can Get integer value for float using the following methods

Code: Select all

```
_FloatToInt64(input) {
VarSetCapacity(Var, 8, 0) ; Variable to hold integer
NumPut(input, Var, 0, "Double" ) ; Input as Float
retval := NumGet(Var, 0, "Int64") ; Retrieve it as 'Signed Integer 64'
VarSetCapacity(Var, 0)
return retval
}
_Int64ToFloat(input) {
VarSetCapacity(Var, 8, 0) ; Variable to hold integer
NumPut(input, Var, 0, "Int64" ) ; Input as Signed Integer 64'
retval := NumGet(Var, 0, "Double") ; Retrieve it as Float
VarSetCapacity(Var, 0)
return retval
}
```

However when the float value is negative _Int64ToFloat() returns a negative value and conversion no longer works. I am guessing the bits are being wrap somehow.

For any other integer my conversion work just fine so I know its not my conversion of the integer.