Now I know how this is done on one line, although I do not understand why my first draft does not work. What I'm trying to do is to save the bottom to another variable by moving the high byte to the right and adding two numbers through OR. However, it simply cuts the bottom half of the hexadecimal and returns the rest.
short int method(short int number) { short int a = 0; for (int x = 8; x < 16; x++){ if ((number & (1 << x)) == 1){ a = a | (1<<x); } } number = number >> 8; short int solution = number | a; return solution;
source share