I have to write an algorithm that can read three bytes of data at a time, as such:
For example, imagine the user inputs: Uof
Uof in binary would be presented as 01010101 01101111 01100110
I need help splitting this into four equal parts of six bits each, as such:
010101 (21)
010110 (22)
111101 (61)
100110 (38)
I’m only allowed to use ints.
I can read the first character, shift it two to the right and get the result 21 no problem.
Getting the 22 makes no sense to me. Any pointers will help, don’t need the exact solution, but what’s something that can get me thinking?
Ask yourself:
where do the 6 bits of each part come from?
how can I move bits to a different position in a value?
how can I combine two values so that only the interesting bits of each are taken?
To help you answer the third question you may also ask yourself: