I'm on a foreign exchange program and studying computer architecture at university. The problem is this university it assumes the students have studied C-programming as their course in basic programming, whereas at my regular university the course in basic programming is ADA.
I am trying to catch up but need some help since I don't really know how C-language is structured.
My current problem:
Shift operations, 32-bit.
Got two functions
int func1 (unsigned word)
{
return (int) ((word<<24) >> 24);
}
int func2 (unsigned word)
{
return ((int) word <<24) >> 24;
}
How does these functions work? I understand the logical shift but not the functions.
My guess is func1 first shift all bits 24 bits to left, and then 24 bits to right, resulting in the 8 LSB will be the same but the 24 MSB will turn into 0's.
Even if my guess is correct I can't see how func2 would work differently. I would greatly appreciate if someone could ellaborate for me.
Examples with 127, 128, 255, 256 as in values?
EDIT: Represented by two's complement