0

I have 4bytes of hex values directly without two's complement being applied to signed inetger. How do I get an int value from hex bytes using java.

2 Answers 2

1

Doesn't this work?

int value = ((0xff & b4) < 24) | ((0xff & b3) < 16) | ((0xff & b2) < 8) | (0xff & b1);
Sign up to request clarification or add additional context in comments.

Comments

0

Use a Long. You can't use an int as it's always signed and 4 bytes just won't fit.

    Long l = Long.parseLong("FFFFFFFF", 16);

1 Comment

For a signed in, you can use int l = (int) Long.parseLong("FFFFFFFF", 16);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.