How to convert float to byte array of length 4 (array of char*)?

前端 未结 3 1566
傲寒
傲寒 2021-02-15 17:23

How to convert float to byte array of length 4 (array of char*) ? I need to send over network some data, tcp, and need to send float as a byte array. ( I know precision to two d

3条回答
  •  抹茶落季
    2021-02-15 18:09

    Just overlay the data in one area, in C

    union dataUnion {  
        float f;  
        char fBuff[sizeof(float)];  
    }  
    // to use:  
    dataUnion myUnion;  
    //  
    myUnion.f = 3.24;  
    for(int i=0;i

提交回复
热议问题