473,404 Members | 2,174 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

convert float to binary

4
how to convert * WITHOUT USING ANY FUNCTION * a float number to binary?
at least if someone can explain me how to do it it would be better then giving me the code itself.
Nov 15 '06 #1
7 46303
Banfa
9,065 Expert Mod 8TB
You are going to have to explain what you want to do better than that.

A float is already held in a binary format.
Nov 15 '06 #2
ayaniv
4
i will give you an example in converting an integer to binary:
the number 245 = 11110101 in binary notation.
i got the answer by algorithm that translate 245 to binary.

i want to write an algorithm for float numbers.
as i will put 12.34 and get its binary notation.

that's it.
Nov 15 '06 #3
Banfa
9,065 Expert Mod 8TB
i will give you an example in converting an integer to binary:
the number 245 = 11110101 in binary notation.
i got the answer by algorithm that translate 245 to binary.

i want to write an algorithm for float numbers.
as i will put 12.34 and get its binary notation.

that's it.
But ints and floats are 2 completely different kettle of fish. Your int (value 245) is actually held in memory in the binary notation you give 11110101.

However the binary notation of the float 12.34 is

1100.010101110000101000111101011100001010001111010 111

But 12.34 in a double variable is held in memory as

10101110 01000111 11100001 01111010
00010100 10101110 00101000 01000000

and 12.34 in a float variable is held in memory as

10100100 01110000 01000101 01000001

So the question is which one are you trying to calculate?
Nov 15 '06 #4
ayaniv
4
i guess it's the last one:
10100100 01110000 01000101 01000001

if you please can tell me how you get to binary notation from 12.34
so i can write the correct algorithm to do it.

thanx
Nov 15 '06 #5
horace1
1,510 Expert 1GB
i guess it's the last one:
10100100 01110000 01000101 01000001

if you please can tell me how you get to binary notation from 12.34
so i can write the correct algorithm to do it.

thanx
Would be worth having a look at URL
http://en.wikipedia.org/wiki/IEEE_754

which describes the IEEE 754 floating point standard
Nov 15 '06 #6
Banfa
9,065 Expert Mod 8TB
i guess it's the last one:
10100100 01110000 01000101 01000001

if you please can tell me how you get to binary notation from 12.34
so i can write the correct algorithm to do it.
As pseudo code it is

Expand|Select|Wrap|Line Numbers
  1. DECLARE FLOAT f
  2. SET f = 12.34
  3. DECLARE BYTE POINTER p
  4. SET p = THE ADDRESS OF f
  5.  
  6. FOR EACH BYTE IN F
  7.     PRINT THE BYTE p POINTS TO IN BINARY
  8.     SET p = p + 1
  9. END FOR
  10.  
Nov 15 '06 #7
horace1
1,510 Expert 1GB
i guess it's the last one:
10100100 01110000 01000101 01000001

if you please can tell me how you get to binary notation from 12.34
so i can write the correct algorithm to do it.

thanx
printing integers in binary is easy so you could have a union, e.g.
Expand|Select|Wrap|Line Numbers
  1. typedef union  {
  2.     float f;
  3.     int i;
  4. } Number;
  5.  
assign the floating point value to f and then print i in binary

you would need to check that int and float were the same size using the sizeof() operator
Nov 16 '06 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Jean-Baptiste PERIN | last post by:
I read 4 bytes from a binary file. These bytes represent a floating point number (mantisse exponent form) How can I get a float from these bytes ?
4
by: jaijai_kumar | last post by:
Select Cast('100.1234' as float) give me the result 100.1234 Now when I convert it back to char I want exactly 100.1234 Select Convert(char(100),Cast('100.1234' as float)) Gives me 100.123 (Here...
2
by: respect | last post by:
i want to convert real float number to 32-bit IEEE binary format in C++ ? plz help me in finding the codes as fast as u can ] Example for input -6.5, the output should be. 1 10000001...
4
by: music4 | last post by:
Greetings, I psinfo_t struct, pr_pctcpu is ushort_t type with comment: "pr_pctcpu is 16 bit binary fractions in the range 0.0 to 1.0 with the binary point to the right of the high-orfer bit...
2
by: bilbo2000 | last post by:
I am trying to read in a binary file which has the data stored as 32 bit float. I have been trying to figure out how to read this in as 32 bit but everytime I try to read it in the best I can do...
35
by: bala.pandu | last post by:
Hello Everyone, When i am assigning a float value and try to print the same, i found the value stored is not the exact value which i gave. int main() { float f1; printf("Enter a float value...
7
by: Mario M. Mueller | last post by:
Hi, I have a binary file containing 3 byte float values (big endian). How can I read them into python? The struct module does not work, since it expects 4 byte floats. Any hints? Mario
7
by: chelle2100 | last post by:
hi... i need to write a converter to convert the text file to a binary file with the following file format... CharacterCount:Unsigned Char(This stores the number of characters that is in the file)...
4
by: Mason | last post by:
I have tried and tried... I'd like to read in a binary file, convert it's 4 byte values into floats, and then save as a .txt file. This works from the command line (import struct); In : f =...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.