473,769 Members | 6,107 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

help needed in converting hex to float......

5 New Member
Heyy Guys...
Im very new to vb.
Im using vb6 and i want to convert a 32 bit ieee 754 number into a floating point number.
for example.
'BE C3 F2 DF' (in hexa representation) should be converted to -0.382712....

i have worked this c++ code over which seems to be running fine.
Need to convert the code in VB.
please help me guys.

Expand|Select|Wrap|Line Numbers
  1. #include<iostream.h>
  2. #include<conio.h>
  3.  
  4.  
  5. void main()
  6. {
  7. //clrscr();
  8. unsigned long int number,value;
  9. int mantissa,exponent;
  10. long int sign;
  11. cout<<"ENTER THE NUMBER.APPEND 0X BEFORE A HEX NUMBER :"<<endl;
  12. cin>>number;
  13. sign=number & 0x80000000;
  14. if(sign==0x80000000) //most significant bit is 1
  15. {
  16. sign=-1;
  17. }
  18. else sign=1;
  19. //cout<<number<<endl;
  20. //mantissa=number & 0x7F800000;
  21. mantissa=number>>23;
  22. mantissa=mantissa & 0xFF;
  23. //cout<<mantissa<<endl;
  24. exponent=mantissa-127;
  25. //cout<<exponent;
  26. value=number & 0x007FFFFF;//extract the characteristic
  27. //cout<<value;
  28. long int mask=0x00800000;
  29. long int masked;
  30. double charac,flot;
  31. for(int i=1;i<24;i++)
  32. {
  33. masked=value & mask;
  34. //cout<<mask<<endl;
  35. if (masked==mask)//value at that bit is 1
  36. {
  37. flot=1.0;
  38. for(int k=0;k<i-1;k++)
  39. {
  40. flot=flot*0.5;
  41. //cout<<flot<<endl;
  42. }
  43. charac=charac+flot;
  44. //cout<<(1/pow(2,i))<<endl;
  45. //cout<<charac<<endl;
  46. }
  47. mask=mask>>1;
  48.  
  49. }
  50. charac=charac+1.0;
  51. //cout<<"charac"<<charac<<endl;
  52. //cout<<"exponent"<<exponent;
  53. float multiplier;
  54. multiplier=1.0;
  55. if(exponent>0)
  56. {
  57. for(i=0;i<exponent;i++)
  58. {
  59. multiplier=multiplier*2;
  60. }
  61. }
  62. if(exponent<0)
  63. {
  64. exponent=exponent*-1;
  65. for(i=0;i<exponent;i++)
  66. {
  67. multiplier=multiplier*2;
  68. }
  69. multiplier=1/multiplier;
  70. }
  71. charac=charac*multiplier*sign;
  72. cout<<charac;
  73. getch();
  74. }
  75.  
  76.  

The funny thing is, the same code when executed in VC++, gives different output. Any views on that...
Mar 2 '07 #1
4 5548
willakawill
1,646 Top Contributor
Hi. Looks like your question is too involved. Try the solution yourself and come back if you are stuck.
Mar 4 '07 #2
Killer42
8,435 Recognized Expert Expert
Hi. Looks like your question is too involved. Try the solution yourself and come back if you are stuck.
A good first step would be to work out (and write down) what the C++ program does, step by step. Once you do that, it should be quite simple to convert the individual steps to VB. And it will ensure that you understand the process.

Of course, given the different capabilities of different languages, the process may end up somewhat different. But the better you understand it, the easier it will be.
Mar 5 '07 #3
mirangk
5 New Member
thanks to everyone.
i finally found d solution using the powerful copymemory( ) function.
thank u again for your efforts.
Mar 6 '07 #4
willakawill
1,646 Top Contributor
thanks to everyone.
i finally found d solution using the powerful copymemory( ) function.
thank u again for your efforts.
Congratulations . I thought you would never find an answer to this.
Mar 6 '07 #5

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

Similar topics

1
4394
by: Giovanni Azua | last post by:
Hello all, I need to return back to TSQL two numeric values from an Extended Stored Procedure developed in C. As result my C dll program produces two float values, the TSQL side expects to have exactly: numeric(10, 5) and numeric. Given that the structure to fill-up is DBNUMERIC defined as:
6
3063
by: Robert P. Stearns | last post by:
I have been trying to convert the following simple table into CSS. <table> <tr><th colspan=2>Header Area</th></tr> <tr><th>Navigation Area</th><th>Information Area</th></tr> <tr><th colspan=2>Footer Area</th></tr> </table> |=========================| | Header Area |
5
1918
by: el prinCipante | last post by:
I'm getting tired of the following error message. Compiler Error message : Error: Need explicit cast to convert from: float to: float * I am trying to use a routine from the Numerical Recipes library called amebsa.c. The routine requires several parameters of the following form. *iter, **p, *yb.... . How does one initialize these variables? If I declare them as pointer (in this case, *yb and *iter) the compiler still tells me that it...
7
2710
by: Tor Aadnevik | last post by:
Hi, I have a problem converting values from Single to double. eg. When the Single value 12.19 is converted to double, the result is 12.1899995803833. Anyone know how to avoid this? Regards Totto
9
30521
by: Gregory.A.Book | last post by:
I am interested in converting sets of 4 bytes to floats in C++. I have a library that reads image data and returns the data as an array of unsigned chars. The image data is stored as 4-byte floats. How can I convert the sets of 4 bytes to floats? Thanks, Greg Book
4
4797
by: Yasin Cepeci | last post by:
I ve get float data from serial port. I ve taken it in the form of hex by modbus protocol. I know it is float but I couldnt convert it there is a few sample data below; B3 33 43 34 = 180.699997 33 33 43 33 = 179.199997 B3 33 43 34= 180.699997 CC CD 43 33=179.800003 But how can I found it. I couldnt resolve it.
10
3245
by: Hank Stalica | last post by:
I'm having this weird problem where my code does the following conversion from string to float: 27000000.0 -27000000.00 2973999.99 -29740000.00 2989999.13 -2989999.25 The number on the left is the string I get after tokenizing a bigger string. The number on the right is the number I get after the conversion.
2
10294
by: IdlePhaedrus | last post by:
Hi, I have a FFT routine that I converted from C++ to VB in a module as follows: Const M_PI = 3.1415926535897931 ' Fast Fourier Transform Public Sub FFT(ByRef rex() As Single, ByRef imx() As Single, ByVal N As UShort) Dim nm1 As UShort = CUShort(N - 1)
7
4787
by: ma740988 | last post by:
Consider the equation (flight dynamics stuff): Yaw (Degrees) = Azimuth Angle(Radians) * 180 (Degrees) / 3.1415926535897932384626433832795 (Radians) There's a valid reason to use single precision floating point types. The number of decimal digits guaranteed to be correct on my implementation is 6. (i.e numeric_limits < float >::digits10 = 6 ) If I'm reading the IEEE standard, I'd could paraphrase the issue
0
9587
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10211
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9863
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7406
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6672
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3958
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 we have to send another system
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.