C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old June 17th, 2004, 11:12 PM
haison3000 haison3000 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 3 haison3000 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
C++ float

Hi,

I have a strange question. I have a bit representation of a floating point number. Now I want to make a float variable wich has value of that representaion. Since C++ does not have bitwise ops for float number, I coudl not do it that way.
Coudl somebody show me a way?
Thank you.

Reply With Quote
  #2  
Old June 18th, 2004, 05:21 AM
kode_monkey kode_monkey is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 367 kode_monkey User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 21 sec
Reputation Power: 6
How is your bit representation stored? Have you tried casting it it to a float ie. (float)bit_rep?

Not entirely sure how I'd do this myself. If you figure it out before someone else gives you the answer please post it here, I'd be interested to know.

-KM-

Reply With Quote
  #3  
Old June 21st, 2004, 04:11 PM
nicat23's Avatar
nicat23 nicat23 is offline
Addicted to Chaos..
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jan 2003
Location: Ft. Worth, TX
Posts: 653 nicat23 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 48 m 34 sec
Reputation Power: 0
Send a message via AIM to nicat23 Send a message via Yahoo to nicat23
Could you give me a little bit more of an explination of what you are trying to do? What program is this for, what operations will it be performing, things like that.. Your statement is a little too general for me to really understand what you need.. Do you have any sample pseudocode or any code that you've worked on so far to share?

Reply With Quote
  #4  
Old June 23rd, 2004, 05:19 PM
haison3000 haison3000 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 3 haison3000 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
The bit representation is a string. Obviously I cannot cast the string to a float.
Someone told me that I could use union. It works but union seems dangerous sometimes so I would like a more elegant solution.

Sorry to get back late.

Reply With Quote
  #5  
Old June 23rd, 2004, 05:23 PM
haison3000 haison3000 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 3 haison3000 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
To get clearer, this is the union method a person told me.


Code:
  
String s="10001000100010001000100010001000";
 
union {float f;char byte[4]} bit;
bit.byte[0]=bit.byte[1]=bit.byte[2]=bit.byte[3]=1<<3; //1<<3 ="1000"
printf("%f",bit.float);
 

Reply With Quote
  #6  
Old October 14th, 2008, 05:00 AM
hlina hlina is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2008
Posts: 1 hlina User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 m 6 sec
Reputation Power: 0
This could be the way you're looking for:

Code:
  
  BYTE bytes[sizeof(float)];
  
  ...
  
  float* floatPtr = reinterpret_cast<float*>(bytes);


Regards,
hlina

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > C++ float


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

Request Your Free Technology Downloads!
 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

Request Your Free Technology Downloads!
 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

Request Your Free Technology Downloads!
 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

Request Your Free Technology Downloads!
 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

Request Your Free Technology Downloads!
 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT