Hex to integer (4 bytes)

Despotars

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.

Bathsheba
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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Hex to integer (4 bytes)

From Dev

converting 4byte hex string to integer

From Dev

UNPACK() 4 bytes into integer PHP sockets

From Dev

How to reverse the 4 bytes of an unsigned integer?

From Dev

sending hex bytes to serial in bash

From Dev

PHP string to hex/bytes?

From Dev

How can I print 4 bytes as an integer

From Dev

how to print 2 or 4 bytes in hex format in C

From Dev

Split random integer into 4 random bytes

From Dev

PHP convert integer to 32 bit (4 Byte) hex for socket programming

From Dev

Properly reading 4 bytes in -Hex- NSData form into its proper data type (float or int) in Swift

From Dev

Java: 4 bytes to 32 bit integer

From Dev

Why IPv4 address is in bytes and can not be in integer range?

From Dev

Combining 4 Bytes To Integer

From Dev

Break up 32-bit hex value into 4 bytes [QB64]

From Dev

How can I print 4 bytes as an integer

From Dev

how to print 2 or 4 bytes in hex format in C

From Dev

Split random integer into 4 random bytes

From Dev

Encode string as hex bytes

From Dev

Java: 4 bytes to 32 bit integer

From Dev

Combining 4 Bytes To Integer

From Dev

Convert Text representation of Hex to hex bytes

From Dev

memset bytewise instead of integer ( 4 bytes )

From Dev

Python String to Hex Bytes

From Dev

Convert 4 bytes to integer using struct

From Dev

Addition of an integer with an hex string

From Dev

hex string to integer

From Dev

jpeg bytes to hex value

From Dev

Long HEX Value Split to 2bytes Hex values or 4bytes Hex Values and convert it to decimal (float) values Using VB.Net