So I was going to make an app to translate different coding languages, like UTF-8, UTF-16, IP Address, Floating Point, RGB, Boolean, but a function for conversions don’t exist. The method of making those conversion require some code to be made and a good understanding with translating each code language between eachother. If there was a button that could translate between 2 of those for example: Floating Point -> Hexidecimal, Boolean -> IP Address, Decimal -> UTF-8/16, then it would make conversions alot better to handle.
That's the fun of learning how to program in App Inventor.
A number of conversions are available
I receive data in hexadecimal format (8 bytes) and I would like to convert it to float but I can't.
example (real) 0x450B9AB0 = 2233.67
I ask for help
From your example string, in javascript:
I also get that result but it's wrong because it's an INT while I need a FLOAT
Floating Point to Hex Converter (gregstoll.com)
Search this board for IEEE754 for the long way in blocks.
float.htm
<!DOCTYPE html>
<html>
<head>
<title>Hexadecimal to Float Conversion</title>
</head>
<body>
<p>Hexadecimal number: 450B9AB0</p>
<p>Float number (Big Endian): <span id="floatValue"></span></p>
<script>
// Convert hexadecimal to float in Big Endian format
const hex = "450B9AB0";
const binary = parseInt(hex, 16).toString(2).padStart(32, '0');
const sign = binary[0] === '1' ? -1 : 1;
const exponent = parseInt(binary.substring(1, 9), 2) - 127;
const mantissa = 1 + parseInt(binary.substring(9), 2) / Math.pow(2, 23);
const floatValue = sign * mantissa * Math.pow(2, exponent);
// Display the result on the HTML page
document.getElementById("floatValue").innerHTML = floatValue.toFixed(3);
</script>
</body>
</html>
from GPT-3.5
could be the solution, i try to turn it into blocks (if i succeed)
thank you very much
Are you sending this data from your device? Are you downloading from the server? Can you modify the floating point encoding?
I receive data from a PV inverter via local network and unfortunately I can't change anything.
i already made a working device written in c for esp8266
now I wanted to make a tablet version
I didn't understand this...
I guess it refers to your script from the previous post.
Actually I receive every 10 seconds a json string, production, consumption, battery in/out, power grid in/out, battery %status.
therefore the values to be converted are many and all in hexadecimal (8 bytes).
I was thinking of creating a procedure with return value and passing the desired hex value.
How is your json string?
Separate each element from your json and convert it to float with the code from the example above.
I will consider your solution but since I'm learning, I want to try to build the block procedure based on your script, I've already started and I hope to succeed.
I will let you know
thank you with all my heart
after some adjustments, this is the final result.
Thanks again for the help
p.s.
Can you explain better how to implement your solution, it could be useful for me in the future
- do I have to create a webserver?
- how do I pass the value to convert?
But you are using Kodular for coding, please ask in Kodular community.