Append/join (bit shift) one binary value before another in Java -
i want able 'insert/append' 1 binary after another. int variables @ moment.
int = 1; int j = 4;
i want bit shift left 3 i
add values together.
for example,
i binary: 1 (1) j binary: 100 (4) result: 1100 (12)
public static int appendbinary(int i, int j) { string istr = integer.tobinarystring(i); string jstr = integer.tobinarystring(j); string binary = istr + jstr; return integer.parseint(binary, 2); }
this method converts , j binary, subs before j, , converts result int. hope helps!
Comments
Post a Comment