Answers for "float to byte array and back c++ with memcpy command"

C++
0

float to byte array and back c++ with memcpy command

void float2Bytes(float val,byte* bytes_array){
  // Create union of shared memory space
  union {
    float float_variable;
    byte temp_array[4];
  } u;
  // Overite bytes of union with float variable
  u.float_variable = val;
  // Assign bytes to input array
  memcpy(bytes_array, u.temp_array, 4);
}
Posted by: Guest on November-19-2020
0

float to byte array and back c++ with memcpy command

// simply this line works perfectly, donnt know why union is taken???
memcpy(c_arr, &f, 4);
Posted by: Guest on September-14-2021

Browse Popular Code Answers by Language