Solved

Convert Binary from Malloced Buffer to a float

Posted on 2004-09-16
6
255 Views
Last Modified: 2010-04-15
I need to convert binary numbers i am getting from malloced data to float so i can divide it, then compare it.
0
Comment
Question by:whinson
  • 4
  • 2
6 Comments
 
LVL 9

Expert Comment

by:ankuratvb
ID: 12081228
What is the problem?

What is the type of the malloced buffer,is it char?

Is it something like:

char *buf;
buf=(char*)malloc(20*sizeof(char));
strcpy(buf,"1100110");
//Now you need the decimal value of 1100110 in a float.Is this what you need?
free(buf);

You need to retrieve only 1 number from the malloced data or more than one?

See this,it might help:
http://www.experts-exchange.com/Programming/Programming_Languages/C/Q_20839804.html

0
 

Author Comment

by:whinson
ID: 12081243
The type is float.  It has multiple items.  
0
 
LVL 9

Accepted Solution

by:
ankuratvb earned 500 total points
ID: 12081322
Ok.So you have the binary numbers stored as floats.Right?

Something like:

float *buf;
buf=(float*)malloc(20*sizeof(float));
buf[0]=11001.11;
buf[1]=10010.11;
.
.
//And you need the decimal values of these individual elements,right?
free(buf);
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

Author Comment

by:whinson
ID: 12081334
I figured it out by myself thanks.  I will give you the points.
0
 
LVL 9

Expert Comment

by:ankuratvb
ID: 12081342
0
 
LVL 9

Expert Comment

by:ankuratvb
ID: 12081355
Nice to know you figured it out yourself. :~)

You also have the option of getting your points refunded by posting your solution and asking for a refund in Community Support.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now