converter string to float

Oi!
Estou estudando para fazer um projeto joystick uso o arduino nano 33 ble. Me desculpem por alguns erros idiotas sou iniciante. Quero movimentar com gyroscoope da placa um cubo através do serviço Ble. Alguém pode me ajudar com esse código estou tendo um erro ao converter string para float. o erro está em “2A58”.

private string DeviceName = "SMART TATTOO";
private string ServiceUUID = "180C";
private string Characteristic = "2A58";
private string Characteristic2 = "2A56";
public float speed = 5.0f;

var string = Characteristic.Split(“,”[0]);

   float GX = float.Parse("2A58"[2]) / speed; 
   float GY = float.Parse("2A58"[4]) / speed; 
   float GZ = float.Parse("2A58"[6]) / speed;

cube.transform.Rotate(new Vector3(GZ, GX, -GY) * Time.deltaTime * speed);

As we said in an earlier post, “2A58” is not a valid number, not at least in the decimal system. That is why you are getting an error when you try and parse from string to float.

However, “2A58” is a valid number in hexadecimal, which counts like this: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F. It’s a convenient way of representing binary numbers. If your Ble service returns hexadecimal numbers, or if you have to communicate with Ble using hexadecimal, then you have to convert them.

(float)int.Parse("2A58", System.Globalization.NumberStyles.AllowHexSpecifier)

int.Parse first of all turns “2A58” into an integer. Then the prefix of (float) turns it into a float. The rather long “System.Globalization.NumberStyles.AllowHexSpecifier” simply allows Parse to work with hexadecimal numbers, otherwise 2A58 would not be valid.