News:

;) This forum is the property of Proton software developers

Main Menu

Converting 2 bytes into float

Started by Yves, May 19, 2025, 11:18 AM

Previous topic - Next topic

Yves

Hello all,
My question will sound silly to most of you but my mind is not getting around it.

I have two byte one is containing the integer and the second byte the decimal. Let say byte1 = 10 and byte2 = 15. How do I convert into a float variable called Result to get 10.15 when I display Hserout Result? Please help. Many thanks in advance.

Yves
Yves

RGV250

Hi,
If you just want to send it to a display or serial port you can just send
dec byte1, ".",dec byte2 or something like that.

Bob

flosigud


Yves

Quote from: RGV250 on May 19, 2025, 12:58 PMHi,
If you just want to send it to a display or serial port you can just send
dec byte1, ".",dec byte2 or something like that.

Bob
Quote from: RGV250 on May 19, 2025, 12:58 PMHi,
If you just want to send it to a display or serial port you can just send
dec byte1, ".",dec byte2 or something like that.

Thanks Bob I know that one but I need to save it in a memory so it has to be put in a variable
Yves

RGV250

Just off the top of my head, can you move byte1 into the float. Divide byte2 by 100 and then add it to the float?

Bob

trastikata

Dim bByte1 As Byte
Dim bByte2 As Byte       
Dim fFloat1 As Float

fFloat1 = bByte1
fFloat1 = fFloat1 + (bByte2 * 0.1)

RGV250

Hi,
you need to multiply by 0.01 as 15 x 0.1 is 1.5 and should be 0.15

Bob

trastikata

Quote from: RGV250 on May 19, 2025, 04:44 PMyou need to multiply by 0.01 as 15 x 0.1 is 1.5 and should be 0.15

Indeed, you are right, thanks.

Dim bByte1 As Byte
Dim bByte2 As Byte       
Dim fFloat1 As Float

    Select bByte2
        Case 0 To 9
            fFloat1 = bByte2 * 0.1
        Case 10 To 99
            fFloat1 = bByte2 * 0.01
    EndSelect

    fFloat1 = fFloat1 + bByte1