Floating Point and other Conversions

With the help of GPT-3.5 you can build an extension...

com.KIO4_HexToDec.aix (6.1 KB)

drererfdsfds

package com.KIO4_HexToDec;
//  Juan Antonio Villalpando - kio4.com

import com.google.appinventor.components.annotations.DesignerComponent;
import com.google.appinventor.components.annotations.SimpleFunction;
import com.google.appinventor.components.annotations.SimpleObject;
import com.google.appinventor.components.common.ComponentCategory;
import com.google.appinventor.components.runtime.*;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;

@DesignerComponent(version = 1,
    description = "Convert Hexadecimal to  Float - Big Endian (ABCD) - KIO4.COM ",
    category = ComponentCategory.EXTENSION,
    nonVisible = true,
    iconName = "") 
@SimpleObject(external = true)
public class KIO4_HexToDec extends AndroidNonvisibleComponent implements Component {
    private ComponentContainer container;
 
    public KIO4_HexToDec(ComponentContainer container) {
        super(container.$form());
    }

@SimpleFunction(description = "Convert hexadecimal to Float - Big Endian (ABCD).")
public String Convert(String hex) {
    byte[] bytes = new byte[4];
    for (int i = 0; i < 4; i++) {
        bytes[i] = (byte) Integer.parseInt(hex.substring(i * 2, i * 2 + 2), 16);
    }
    ByteBuffer buffer = ByteBuffer.wrap(bytes).order(ByteOrder.BIG_ENDIAN);
    float floatValue = buffer.getFloat();
    return String.valueOf(floatValue);
}
}	// ==> FIN

1 Like