Learn Trix
Learn Trix

Reputation: 13

Need some help in java Bit operations?

I have a byte array as: 00SSSMMM

I want to retrieve SSS and MMM values as int values.

Can someone help me in implementing this in java ?

Thanks.

Upvotes: 0

Views: 47

Answers (1)

Peter Lawrey
Peter Lawrey

Reputation: 533442

I think you mean

int x = ...
int m = x & 0b111;
int s = (x >> 3) & 0b111;

Upvotes: 1

Related Questions