Click here to Skip to main content
15,906,081 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionConversion Problem Pin
Andy20214-Sep-07 4:47
Andy20214-Sep-07 4:47 
QuestionRe: Conversion Problem Pin
David Crow14-Sep-07 4:52
David Crow14-Sep-07 4:52 
AnswerRe: Conversion Problem Pin
Andy20214-Sep-07 5:05
Andy20214-Sep-07 5:05 
QuestionRe: Conversion Problem Pin
David Crow14-Sep-07 5:31
David Crow14-Sep-07 5:31 
AnswerRe: Conversion Problem Pin
Andy20214-Sep-07 9:45
Andy20214-Sep-07 9:45 
GeneralRe: Conversion Problem Pin
Russell'14-Sep-07 7:20
Russell'14-Sep-07 7:20 
AnswerRe: Conversion Problem Pin
Russell'14-Sep-07 4:54
Russell'14-Sep-07 4:54 
AnswerRe: Conversion Problem Pin
Nathan Holt at EMOM14-Sep-07 10:30
Nathan Holt at EMOM14-Sep-07 10:30 
Andy202 wrote:
I receive a 20 word message and two words of this message define a floating value;

unsigned short message [20]; // Message buffer

e.g. message [2] and message[3] define a float with the mantissa in the lower byte of message[3].

Could I get the floating value by doing this:-

union
{
  float data;
  unsigned short buff[2];
}convert;

convert.buff[0] = message[2];
convert.buff[1] = message[3];

float val = convert.data;

Or what is the best way to get this 32 bit embedded floating point value.

Andy


Something like that would work if you used the fixes I made in your quote. However, it would be easier to just use
float result = *(reinterpret_cast<float *>(message + 2);

GeneralRe: Conversion Problem Pin
Andy20214-Sep-07 11:24
Andy20214-Sep-07 11:24 
Questionstring or int? Pin
VonHagNDaz14-Sep-07 4:16
VonHagNDaz14-Sep-07 4:16 
AnswerRe: string or int? Pin
Christian Graus14-Sep-07 4:17
protectorChristian Graus14-Sep-07 4:17 
GeneralRe: string or int? Pin
VonHagNDaz14-Sep-07 4:20
VonHagNDaz14-Sep-07 4:20 
GeneralRe: string or int? Pin
led mike14-Sep-07 4:29
led mike14-Sep-07 4:29 
GeneralRe: string or int? Pin
VonHagNDaz14-Sep-07 4:32
VonHagNDaz14-Sep-07 4:32 
GeneralRe: string or int? Pin
led mike14-Sep-07 4:44
led mike14-Sep-07 4:44 
GeneralRe: string or int? Pin
VonHagNDaz14-Sep-07 4:53
VonHagNDaz14-Sep-07 4:53 
GeneralRe: string or int? Pin
David Crow14-Sep-07 4:23
David Crow14-Sep-07 4:23 
QuestionUnsure of reason for error. Pin
Chris Meech14-Sep-07 4:02
Chris Meech14-Sep-07 4:02 
AnswerRe: Unsure of reason for error. Pin
jhwurmbach14-Sep-07 4:07
jhwurmbach14-Sep-07 4:07 
GeneralRe: Unsure of reason for error. Pin
Chris Meech14-Sep-07 4:40
Chris Meech14-Sep-07 4:40 
GeneralRe: Unsure of reason for error. Pin
jhwurmbach14-Sep-07 4:46
jhwurmbach14-Sep-07 4:46 
AnswerRe: Unsure of reason for error. Pin
Mark Salsbery14-Sep-07 7:04
Mark Salsbery14-Sep-07 7:04 
GeneralRe: Unsure of reason for error. Pin
Chris Meech14-Sep-07 7:29
Chris Meech14-Sep-07 7:29 
Questiondo you think you raelly know the difference of public and private? Pin
includeh1014-Sep-07 3:47
includeh1014-Sep-07 3:47 
QuestionRe: do you think you raelly know the difference of public and private? Pin
Nelek14-Sep-07 4:07
protectorNelek14-Sep-07 4:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.