How to convert signed ascii hex to float value
Hi,
I have a requirement to convert IEEE ascii hex to float value.
Following code is working for +ve float value but it didn't work for -ve.
public static float hexToFloat(String str){
float floatVal= 0.0f;
int decimalValue =Integer.parseInt(str,16);
floatVal=Float.intBitsToFloat(decimalValue );
return floatVal;
for example "BE4CE1E6" should return -0.20 . (i verified in http://babbage.cs.qc.edu/IEEE-754/32bit.html )
For the above string I am getting number format exception.
pls help me.
The problem is the parseInt method. It can only process numbers up to 2147483647 or 7FFFFFFF. Because that method expects a signed number.
The solution is to use Long.parseLong() instead.
public static float hexToFloat(String str){
float floatVal= 0.0f;
int decimalValue =(int)Long.parseLong(str,16);
floatVal=Float.intBitsToFloat(decimalValue );
return floatVal;
}
Similar Messages
-
How to convert an ascii file into dBase .dbf file type
Does any one out there know how to convert an ascii file(which is generated from PL/SQL script) into a .dbf (dBaseIII) file type? Thanks in advance.
I haven't worked with dBase for about 20 years, but I seem to recall it having an IMPORT command for that purpose. But maybe I'm wrong...
-
How to extract an integer or a float value from a String of characters
Hi i have a problem getting to a float value within a string of characters..
for instance the string is
"numberItem xxxxxxxxx 700.0" (each x is a space..the forum wouldnt let me put normal spaces for some reason)
how do i store 700.0 in a float variable
remember the string is obtained from an inputfile
so far i got the program to store the inputfile data line by line in a String array..i tried tokenizing the string to get to the the float value but since i have mulitple spaces within my string, the token method only gets "numberItem" from the above String
This is all i have so far:
String c;
String Array[] =new String[g]; (i used a while loop to obtain g(the nubmer of lines in the file))
while((c=(cr.readLine()))!=null)
Array[coun]=c;
it would be reallllllllllllllllllllllllllllllllllllllly easy if there was a predefined method to extract numeric values from a string in java..
Edited by: badmash on Feb 18, 2009 5:50 PM
Edited by: badmash on Feb 18, 2009 5:50 PM
Edited by: badmash on Feb 18, 2009 5:55 PMbadmash wrote:
Hi i have a problem getting to a float value within a string of characters..
for instance the string is
"numberItem xxxxxxxxx 700.0" (each x is a space..the forum wouldnt let me put normal spaces for some reason)
with the space included
how do i store 700.0 in a float variable
remember the string is obtained from an inputfile
so far i got the program to store the inputfile data line by line in a String array..i tried tokenizing the string to get to the the float value but since i have mulitple spaces within my string, the token method only gets "numberItem" from the above StringHuh?
Not true.
Anyway why not use string split, split on spaces and grab the last element (which by the format you posted would be your 700.0)
Then there is the Float.parseFloat method.
It is easy.
And another thing why not use a List of Strings if you want to store each line? (And why did you post that code which doesn't really have anything to do with your problem?) Also in future please use the code formatting tags when posting code. Select the code you are posting in the message box and click the CODE button. -
How to convert an time interval into float ?
Dear oracle Experts,
I have a question concerning time conversion.
I would like to convert an interval like e.g.
tsDuration INTERVAL DAY (9) TO SECOND;
into a float which describes the interval as a fraction of a day where
the pre decimal position is the number of days and the post decimal
position the fraction of a day in a decimal syntax of the day.
Are there conversion function available in Oracle 10g with which I
could perform that task ?
If there isn't a conversion function for that.what's the best way to do it ?
Best regards,
DanielHi Srini
1. Copy/Paste Webdynpro components in the new project as was suggested before
2. Or create new project, copy _comp folder from old project to the new one. But, do not forget to update .dcdef & .project files manually after this. You have to set the correct project name in .dcdef and set the correct local project path in .project.
BR, Sergei -
Convert non-ASCII character to decimal value
Hi all,
I have the following problem:
When reading a String containing the full spectrum of UTF-8 characters from a BufferedReader:
How can I get the decimal value of the String's characters outside the ASCII range?
When I try to do a MyBufferedReader.read(), I get the int value 65533 for these characters, instead of their real value in the UTF-8 set.
Can anyone help?
Thanks!
DreThat's the character you get when you try to decode a character with no valid decoding. Of course there aren't any such characters for UTF-8. Therefore whatever you did, don't do that. More specifically: you've already got a String, don't do anything which involves converting it to bytes. That's completely unnecessary.
Or perhaps the problem is the way you create the String in the first place. Who knows? -
How to convert from scientific notations to double value ?
Hi all,
i need to convert a string 2E-23 to corresponding double values so that i can compare it one more existing double value. Is there any API present for this ?
Thanks and regards,
rosamama.Note: This thread was originally posted in the Swing forum, but moved to this forum for closer topic alignment.
-
How to convert a string to a currency value ? getting a dump with exception
Hi,
I am getting a exception not caught in CX_SY_CONVERSION_NO_NUMBER.
I am trying to convert a string value with ',' to a currency value.
I tried using Replace and Condense. But the error still persists.
Is there a FM or a casting that I can use?
Cheers
KiranHi,
Sorry I got my question wrong. I have a problem - that when I'm trying to pass a value from a string to a currency field.
But, the currency field is a field symbol.
so, I have
data abc type string.
abc = "5345"
<curr_val> = abc.
now <curr_val> = 0.000
Please suggest. -
How to convert result rows into comma separated values
hi,
Version
BANNER
Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production
PL/SQL Release 11.1.0.7.0 - Production
CORE 11.1.0.7.0 Production
TNS for Linux: Version 11.1.0.7.0 - Production
NLSRTL Version 11.1.0.7.0 - ProductionQuery
Select distinct prcdr_code from procedure p where P.PRCDR_CTGRY_LKPCD='P' ;
Output
PRCDR_CODE
0001F
0001T
0002F
0002T
0003F
0003T
0004F
0005F
0005T
0006F
0006T
0007F
0007T
0008F
0008T
0009F
0009T
000VA
000VG
Desired Output
0001F,0001T,0002F,0002T .................
My work
i tried this .....
Select distinct wm_concat(prcdr_code) as re from procedure p where P.PRCDR_CTGRY_LKPCD='P' ;
But i got ORA-22813: operand value exceeds system limits error
Please help me ..Thanks,
P Prakash
Edited by: prakash on Jan 4, 2012 9:05 AMAggregating CLOB's....
user defined aggregate function can do it...
create or replace type clobagg_type as object
text clob,
static function ODCIAggregateInitialize(sctx in out clobagg_type) return number,
member function ODCIAggregateIterate(self in out clobagg_type, value in clob) return number,
member function ODCIAggregateTerminate(self in clobagg_type, returnvalue out clob, flags in number) return number,
member function ODCIAggregateMerge(self in out clobagg_type, ctx2 in clobagg_type) return number
create or replace type body clobagg_type is
static function ODCIAggregateInitialize(sctx in out clobagg_type) return number is
begin
sctx := clobagg_type(null) ;
return ODCIConst.Success ;
end;
member function ODCIAggregateIterate(self in out clobagg_type, value in clob) return number is
begin
self.text := self.text || value ;
return ODCIConst.Success;
end;
member function ODCIAggregateTerminate(self in clobagg_type, returnvalue out clob, flags in number) return number is
begin
returnValue := self.text;
return ODCIConst.Success;
end;
member function ODCIAggregateMerge(self in out clobagg_type, ctx2 in clobagg_type) return number is
begin
self.text := self.text || ctx2.text;
return ODCIConst.Success;
end;
end;
create or replace function clobagg(input clob) return clob
deterministic
parallel_enable
aggregate using clobagg_type;
SQL> select trim(',' from clobagg(ename||',')) as enames from emp;
ENAMES
SMITH,ALLEN,WARD,JONES,MARTIN,BLAKE,CLARK,SCOTT,KING,TURNER,ADAMS,JAMES,FORD,MILLER
SQL> ed
Wrote file afiedt.buf
1 with t as
2 (select 'PFL' c1, 0 c2,110 c3 from dual union all
3 select 'LHL', 0 ,111 from dual union all
4 select 'PHL', 1, 111 from dual union all
5 select 'CHL', 2, 111 from dual union all
6 select 'DHL', 0, 112 from dual union all
7 select 'VHL', 1, 112 from dual union all
8 select 'CPHL', 0, 114 from dual union all
9 select 'WDCL', 1, 114 from dual union all
10 select 'AHL' ,2 ,114 from dual union all
11 select 'NFDL', 3, 114 from dual)
12 --
13 -- end of test data
14 --
15 select trim(clobagg(c1||' ')) as c1, c3
16 from (select * from t order by c3, c2)
17 group by c3
18* order by c3
SQL> /
C1 C3
PFL 110
LHL CHL PHL 111
DHL VHL 112
CPHL AHL NFDL WDCL 114 -
How to Convert Binary Data in Binary File
hi,
my telecom client puts a binary file which is asn.1 encoded with BER.
how to handle binary data in java.
how to convert binary to hexa to ascii format
how to convert binary to octet to ascii format
please help me in this.
regards,
s.mohamed asifYou don't need to convert the data.
Only you can do is print it in that formats, like it:
public static String byteArrayToHex(byte[] b) {
StringBuffer sb = new StringBuffer();
for (int i = 0; i < b.length; i++)
sb.append(Integer.toHexString(b&255) + " ");
return sb.toString();
take a look at this
http://java.sun.com/docs/books/tutorial/essential/io/ -
How do I convert the ASCII character % ,which is 25h, to a hex number 25h. I've tried using the scan value VI but I get a zero in the value field.
You can use String to Byte Array for this.
-
I have to convert a bit Hex string into a float. I built a vi from the following C code, but it only works on positive numbers. Any suggestions?
sample16 = (short) ((MSB << 8) | LSB);
sample = (float)sample16/32768.0;
sample*=10.0;
Attachments:
Parse Response.vi 13 KB[email protected] wrote:
Hi altenbach
The data is come from flowmeter by MODBUS.
Thanks
Hong
You are not giving us any useful information. Look up the manual of your device. Somewhere in there should be a definition of how the numbers are built up.
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines -
How to convert a string to hex in TestStand
Hi everyone, I think this is a fairly easy question to answer but I am newer to TestStand.
In one step I am pulling in the Serial Number of a Device (which is alpha and numeric characters) and storing it as a String Local called Local.SerialNumberString. In the following step I need to convert this Local to a Hex value and store it as Locals.SerialNumberHex
Here is the data representation I need to take place:
Locals.SerialNumberString = ABC123456
and would like to know of a function that would convert to the following:
Locals.SerialNumberHex = 414243313233343536
How can this be done?
Thanks so much!It looks like what you are asking for is more than just converting to hex, it looks like you want to convert the characters in the string to their ascii value representation and then convert that to hex.
1) Use a for loop Locals.i = 0; Locals.i < Len(Locals.SerialNumberString); Locals.i++
2) Inside the loop do: Locals.SerialNumberHex += Str(Asc(Mid(Locals.SerialNumberString, Locals.i, 1)), "%.2x")
Hope this helps,
-Doug -
Convert and split Hexa number into ASCII
Hai
How to convert Hexa number to equivalent ASCII number
i attached my VI
thanks
sk
I am using LabVIEW 7.1
Attachments:
HEX2ASCII.vi 31 KBIt really depends on what you want. For example you want to "split the hexa number 1A into 1 and A". Should the output be a string or another U8 number?
Attached are a few possibilities.
LabVIEW Champion . Do more with less code and in less time .
Attachments:
HEX2ASCIImod.vi 51 KB -
I have a serial device that returns a hex number but in ascii format(!).
For example:
Instead of returning FF0A (viewed in a string indicator set to Hex display), it returns ff0a (as viewed in a string indicator set to normal display). But the data actually represents FF 0A.
My question is how can I convert ff0a (ascii) to FF 0A (hex)?
Thanks in advance!
Solved!
Go to Solution.Hexadecimal String to Number.
Remember:
The LabVIEW Help is there to help you.
The functions palette has a search capabitility.
Message Edited by smercurio_fc on 06-15-2010 09:22 AM
Attachments:
Example_VI_BD.png 1 KB -
How to convert hex into a string value
hei evryone!
can anyone please help me on how to convert a hex value into a string suppose.. Example i want to convert 4275646479 which is a hex value, into a string "BUDDY"? how will i do that???
Any suggestion, tutorial site would be appreciated?
Thx!something like this will convert string to byte[]
e.g.
you want to convert following.
656667 => ABC
String toConvert = "656667";
byte[] returnVal = String2byteArr (toConvert );
String FinalStr = new String(returnVal);
public static byte[] String2byteArr(String Result)
byte[] byteRet = new byte[Result.length()/2];
int k=0;
for (int j=0; j<(Result.length()); j+=2)
try
Integer I = new Integer (0);
I = I.decode ("0x"+Result.substring(j, j+2));
int i = I.intValue ();
if (i > 127)
i = i - 256;
byteRet[k++] = new Integer(i).byteValue();
catch(Exception e)
System.err.println(e);
return byteRet;
}// String2byteArr
Hope this will help you, So that i can get 3$ (:-)
Avi
Maybe you are looking for
-
Final Cut Pro locking up when view all clips selected in the browser.
-
Hi everyone. How can download adobe acrobat 9 standard
i have serial key for acrobat 9 standard but I couldn't find on web
-
The Iphone available in france on appel store?
Hello, (I'm sorry, I don't speak english very well, because I'm french) According Appel, the Iphone would only be available in France on November 29. But visiting the site, we saw the french could buy from this page: http://store.apple.com/Apple/WebO
-
I have photoshop elements 10 on old computer
Can I download or upgrade my photoshop elements 10 that I had on my old computer?
-
After updating to iTunes 7, can't find "purchased" playlist in Front Row
After updating to iTunes 7 (and QT 7), I discovered that Apple has moved the "purchased" list of music to the "store" section. Therefore, I cannot access my "purchased" list from Front Row. Does anyone know how to fix this? My primary use for Front R