I'm working with ZigBee, I receive data from a sensor of a end device, and I want to convert from hex to int. The data are from 4bytes, this information is regarding the battery, an example of what I get would be this: "00 00 00 e1" (but without blanks) and I need to pass this on to voltages, but first I think I need to pass it to int.
Anyone can help me please? I'm doing my application for Android.
Thank you in advance.
int n = (int)Long.parseLong(st.replaceAll("\\s+",""), 16);
(where st is your string) does it. Two things:
The replaceAll
strips out any white space.
I go via the Long
parser to circumvent NumberFormatExceptions
for negatives
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments