# Thread: How do i convert a int to a binary with bitwise operators only?

1. Member
Join Date
May 2010
Posts
25
Rep Power
0
i don't know... i assume i need a counter and if it's not 31, then increment it to 0 to fill it up
for the 32 place, check it's positive or not... then use 1.

2. Member
Join Date
May 2010
Posts
25
Rep Power
0
NUM is an int.
i was thinking that it will check the places it has computed for the binary places... and then if it will fill the remaining with 0

last bit(31th) i will check positive or neg.

3. Originally Posted by diskhub
NUM is an int.
i was thinking that it will check the places it has computed for the binary places... and then if it will fill the remaining with 0

last bit(31th) i will check positive or neg.
It will, and the most difficult part. Go through the API code first of all.

4. Originally Posted by diskhub
so no guide?
i thought of one... but might not be a prof way...

that's why i wanted to see what u expert can do... nevermind, i guess u guys are also not used to this tricky question. :D
No, we forgot all about it or we never learned how to use them ;-) btw don't use that ugly expression NUM-(NUM>>1<<1) use the much simpler expression NUM&1 instead if you really want to reinvent the wheel. Also btw if you want to chop off the rightmost bit of a number in a loop you end up with all the bits generated from right to left; better use a mask 0x80000000, use that and shift it to the right at every loop pass until your mask becomes zero.

kind regards,

Jos

5. Member
Join Date
May 2010
Posts
25
Rep Power
0
yup, agree. NUM&1 is so much better.
Thanks everyone.

6. Member
Join Date
May 2010
Posts
25
Rep Power
0
thanks for your concern
I read ur sample code and modified it
and it works perfectly.

cheers.

7. Welcome :)

If you've solved the problem please mark the thread solved. I hope you know that how to do it.

8. One more thing I want to added.

What you've done is really nice work. But it needs really hard work, really difficult stuff. That's why I guide you to look at how Suns' people handle this.

At the same time the provide easy access to use them in easy way, no need to implement again and again. :)

Page 2 of 2 First 12

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•