I was inspired to solve the problem posted by someone recently about bit operations. However, I am afraid to ask for too much help because I really don't want to just post the answer out here for that person to steal. So I am going to try to ask for very specific help on a couple things I'm not exactly sure on.
How many bits are in an int? I have written a method to print out 32 characters, either 1 or 0, based on the int value you pass in.
(I don't want to give away the code
) anyway, my for loop starts at 0, and loops until i < 31. That seems to work fine (when I start my bit mask at 0x40000000), but I thought I should have been going until 32. I think it has something to do with having the one bit representing the sign, but the behavior of the method changes completely when I just loop until 32 and start my bit mask at 0x80000000. Basically, if the mask starts at 0x40000000 and loops 31 times, the bit representation that prints out is correct. But if the mask starts at 0x80000000 and I loop 32 times, the output is all 0's. I was expecting to see the correct bit
pattern again, and if the number was negative, the bit to the very left (I guess they'd call it bit 31) would be 1 instead of 0.
I hope I have explained what I'm trying to say... if anybody has any input I'd appreciate it.