i was hopefully after some tips opposed to solutions as this is homework and i want to solve it myself
I am firstly very new to C. In fact i have never done any before, though i have previous java experience from modules at university.
I am trying to write a programme that converts a single integer in to binary. I am only allowed to use bitwise operations and no library functions
Can anyone possibly suggest some ideas about how i would go about doing this. Obviously i dont want code or anything, just some ideas as to what avenues to explore as currenty i am a little confused and have no plan of attack. Well, make that a lot confused :D
thanks very much
Think about about what you can do with bitwise operators.
E.g. you can test whether a bit is 1 or 0 like this:
int bit = value & 1;
You can also shift the bits in an int like this:
val = val >> 1;
To test the i'th bit in an int you can do this:
int bit = (value >> i) & 1;
Hopefully that's enough hints to get you started.
Tear it apart bit by bit. Use shifting. Handling more than one bit at a time can be done with a lookup table.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With