1

How to convert array of floats to array of bytes in Arduino. Basically convert all float variables of the array to bytes (and round all variables to the nearest integral value) in an efficient way.

Convert this:

float mlx90640To[768];

to:

byte bytearray[768];
1
  • 1
    What's wrong with a simple loop? Commented Jun 20, 2020 at 7:16

1 Answer 1

1

I guess that I maybe do not fully understand the question. It maybe an XY-Problem.

But a fast and efficient solution could be the below.

#include <iostream>
#include <cmath>

using byte = unsigned char;

float mlx90640To[768];
byte bytearray[768];

int main() {

    // Convert all float values
    for (size_t i{}; i < 768; ++i)
        bytearray[i] = static_cast<byte>(std::lround(mlx90640To[i]));

    return 0;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.