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
- #include<iostream.h>
- #include<conio.h>
- void main()
- {
- //clrscr();
- unsigned long int number,value;
- int mantissa,exponent;
- long int sign;
- cout<<"ENTER THE NUMBER.APPEND 0X BEFORE A HEX NUMBER :"<<endl;
- cin>>number;
- sign=number & 0x80000000;
- if(sign==0x80000000) //most significant bit is 1
- {
- sign=-1;
- }
- else sign=1;
- //cout<<number<<endl;
- //mantissa=number & 0x7F800000;
- mantissa=number>>23;
- mantissa=mantissa & 0xFF;
- //cout<<mantissa<<endl;
- exponent=mantissa-127;
- //cout<<exponent;
- value=number & 0x007FFFFF;//extract the characteristic
- //cout<<value;
- long int mask=0x00800000;
- long int masked;
- double charac,flot;
- for(int i=1;i<24;i++)
- {
- masked=value & mask;
- //cout<<mask<<endl;
- if (masked==mask)//value at that bit is 1
- {
- flot=1.0;
- for(int k=0;k<i-1;k++)
- {
- flot=flot*0.5;
- //cout<<flot<<endl;
- }
- charac=charac+flot;
- //cout<<(1/pow(2,i))<<endl;
- //cout<<charac<<endl;
- }
- mask=mask>>1;
- }
- charac=charac+1.0;
- //cout<<"charac"<<charac<<endl;
- //cout<<"exponent"<<exponent;
- float multiplier;
- multiplier=1.0;
- if(exponent>0)
- {
- for(i=0;i<exponent;i++)
- {
- multiplier=multiplier*2;
- }
- }
- if(exponent<0)
- {
- exponent=exponent*-1;
- for(i=0;i<exponent;i++)
- {
- multiplier=multiplier*2;
- }
- multiplier=1/multiplier;
- }
- charac=charac*multiplier*sign;
- cout<<charac;
- getch();
- }
The funny thing is, the same code when executed in VC++, gives different output. Any views on that...