How to send double value as 8 uint8 values??
-
Hi all, I am currently working on Serial Interface between a control box and PC and want to send/receive double values from Pc to the box as 8 uint8 values since the box only accepts in uint8 form. For that i thought as follows : to get that double value (64 bits) in binary form and get the last 8 bits with &(and) operator and shifting bits to right till all bits are finished,namely : double var; char var2send[8]; % in array var2send[0]= var & 0x00000000000000ff % last 8 bits with & operator var>>8; %shifting bits var2send[1]= var & 0x00000000000000ff var>>8; . . % and sending this array as output . But in this code, i received an error that says i cant use double with & operators so that must be converted 64 bit long form!! How can i manage to do this?? or anyone has better way or suggestion? I hope i could clearly explain my problem. I would be very pleased if you could help me! Thanks a lot! Cahit
-
Hi all, I am currently working on Serial Interface between a control box and PC and want to send/receive double values from Pc to the box as 8 uint8 values since the box only accepts in uint8 form. For that i thought as follows : to get that double value (64 bits) in binary form and get the last 8 bits with &(and) operator and shifting bits to right till all bits are finished,namely : double var; char var2send[8]; % in array var2send[0]= var & 0x00000000000000ff % last 8 bits with & operator var>>8; %shifting bits var2send[1]= var & 0x00000000000000ff var>>8; . . % and sending this array as output . But in this code, i received an error that says i cant use double with & operators so that must be converted 64 bit long form!! How can i manage to do this?? or anyone has better way or suggestion? I hope i could clearly explain my problem. I would be very pleased if you could help me! Thanks a lot! Cahit
Yes, binary operations only work with integers. Multiply by whatever number of decimals you want, then cast to int. BTW, this is the wrong forum, this is not a managed C++ question
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
-
Yes, binary operations only work with integers. Multiply by whatever number of decimals you want, then cast to int. BTW, this is the wrong forum, this is not a managed C++ question
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog