473,503 Members | 1,669 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How can I convert binary float number into a decimal float number ?

14 New Member
How can I convert binary float number into a decimal float number ?
Aug 16 '10 #1
7 4196
Dormilich
8,658 Recognized Expert Moderator Expert
you do this as integer via parseInt() by passing the input’s radix (second parameter). (binary numbers usually ain’t floats)
Aug 16 '10 #2
Udara chathuranga
14 New Member
I am a beginner.So can you explain this that answer with an example.
Thanks
Aug 17 '10 #3
Dormilich
8,658 Recognized Expert Moderator Expert
in JavaScript there is exactly one number type: float (IEEE 774). that is, a binary number must be a string consisting of 0s and 1s. for string conversion you have 3 methods:
- Number() (the constructor for the Number objects)
- parseFloat() (parse a string into a float (obviously a decimal float))
- parseInt() (parse a string as integer into a float using the given radix)

thus if you have any number that’s not decimal, you have to apply parseInt(), as that’s the only function where you can set the radix.
Aug 17 '10 #4
Udara chathuranga
14 New Member
Thank you sir I understood.
But please check is it possible to develope the script below, to convert binary float number in to decimal float number.


Expand|Select|Wrap|Line Numbers
  1. <html xmlns="http://www.w3.org/1999/xhtml"> 
  2.      <head></head>
  3.   <body>
  4.  <script type="text/javascript">
  5.    function ConvertToBinary(){
  6.         var numberValue = document.getElementById('NumberInput').value;
  7.        var decNumber = Number(numberValue);
  8.          var binaryNumber = decNumber.toString(2).toUpperCase();
  9.  
  10.          document.getElementById('Result').value = binaryNumber;
  11.        }
  12.        function ConvertToDec(){
  13.          var binaryNumber = document.getElementById('NumberInput').value;
  14.        var decNumber = parseInt(binaryNumber, 2);
  15.          document.getElementById('Result').value = decNumber;
  16.       }
  17.     </script>
  18.  
  19.      <div style="text-align:center">
  20.        Number: <input type="text" id="NumberInput"></input>
  21.        Result: <input type="text" id="Result"></input>
  22.       <br/>
  23.       <button onclick="ConvertToBinary();">Convert To Binary</button>
  24.       <button onclick="ConvertToDec();">Convert To Decimal</button>
  25.      <br />
  26.     </div>
  27.    </body>
  28.  </html>
Aug 17 '10 #5
Dormilich
8,658 Recognized Expert Moderator Expert
there’s one important thing you forgot:

© 2010 Frinavale


if you copy, copy right (pun intended)
Aug 17 '10 #6
Udara chathuranga
14 New Member
Thank you sir I understood.
But please check is it possible to develope the script below, to convert binary float number in to decimal float number.



Expand|Select|Wrap|Line Numbers
  1.     <html xmlns="http://www.w3.org/1999/xhtml"> 
  2.          <head></head>
  3.      <body>
  4.   <script type="text/javascript">
  5.      function ConvertToBinary(){
  6.      var numberValue = document.getElementById('NumberInput').value;
  7.          var decNumber = Number(numberValue);
  8.           var binaryNumber = decNumber.toString(2).toUpperCase();
  9.  
  10.          document.getElementById('Result').value = binaryNumber;
  11.          }
  12.        function ConvertToDec(){
  13.         var binaryNumber = document.getElementById('NumberInput').value;
  14.         var decNumber = parseInt(binaryNumber, 2);
  15.          document.getElementById('Result').value = decNumber;
  16.        }
  17.     </script>
  18.  
  19.       <div style="text-align:center">
  20.         Number: <input type="text" id="NumberInput"></input>
  21.         Result: <input type="text" id="Result"></input>
  22.       <br/>
  23.        <button onclick="ConvertToBinary();">Convert To Binary</button>
  24.        <button onclick="ConvertToDec();">Convert To Decimal</button>
  25.        <br />
  26.      </div>
  27.    </body>
  28.   </html>
Aug 19 '10 #7
Dormilich
8,658 Recognized Expert Moderator Expert
I would assume Frinavale doesn’t publish code that’s not working.
Aug 19 '10 #8

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

Similar topics

0
2897
by: j2ee | last post by:
hello. could anyone tell me why my msqsl db is still storing (displaying) 10.0 instead of 10.00 on a float (2), decimal(2), numeric(2) field? Thanks
13
41774
by: Hako | last post by:
I try this command: >>> import string >>> string.atoi('78',16) 120 this is 120 not 4E. Someone can tell me how to convert a decimal number to hex number? Can print A, B, C,DEF. Thank you.
2
7154
by: gokul | last post by:
hi, i copied example.doc files from windows to linux. now i open the example.doc file in linux it's open only in binary format. How to convert binary format to human readable format(using C...
2
4482
by: Tukeind | last post by:
Hello, I am receiving the following error: error C2065: 'to_binary' : undeclared identifier while running the code below. If anyone can help I'll appreciate it? Thank you, Tukeind
9
3459
by: Leo jay | last post by:
i'd like to implement a class template to convert binary numbers to decimal at compile time. and my test cases are: BOOST_STATIC_ASSERT((bin<1111,1111,1111,1111>::value == 65535));...
1
2961
by: sarbeswar | last post by:
How to convert binary data to text format in visual basic 6
3
8556
karthickkuchanur
by: karthickkuchanur | last post by:
hai, i want to alter my data type into number to float i execute query like alter table preducationalhistory modify percentage float(3) but i have the error in it please reply
1
7189
by: Swan | last post by:
I am sending binary data from ASP to dll in VB.I am able to receive the data,but it is in binary format.can anybody plz tell me how to convert binary data to original text in VB.(I am saving data in...
22
11723
by: xiao | last post by:
Can I fullfill this task? Using fred and fwrite?
17
6772
by: D'Arcy J.M. Cain | last post by:
I'm not sure I follow this logic. Can someone explain why float and integer can be compared with each other and decimal can be compared to integer but decimal can't be compared to float? True...
0
7199
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,...
1
6982
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
7451
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...
1
5000
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...
0
4667
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3161
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3150
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1501
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
731
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.