> Bit-wise operations..?

Bit-wise operations..?

Posted at: 2014-12-18 
so let me get this straight. you take in an integer (most likely as a user input)

and want to output an integer representation of the last 4 bits of the integer the user inputted and then the same with the first 4 bits?

I'm not going to write code for you but I will guide you a bit.

first, I'm hoping that you know how to convert between decimal and binary. if not, then please take a look at this link.

http://www.wikihow.com/Convert-from-Deci...

to turn this into code, you'll want to make an array of 8 elements (preferably of type String)

you'll want to make a recursive function that returns the remainder on division (modulo operation %) and calls itself with 1/2 of the initial number until it reaches and input of 1. as each of those remainders is returned, you will use them to fill in the array. make sure to fill it in an appropriate order.

with the array filled, you can the make strings made up of the first and last 4 elements.

cast these strings to integers and then print them out.

a. int result = x & 0x0000000F;

b. assuming you mean bits 8-5

int result = x & 0x000000F0;

a) Write an expression that would give an integer that corresponds to the last 4 bits of x

b) Assuming x is an integer, write an expression that would give an integer that corresponds to the next 4 bits of x