446,389 Members | 1,795 Online
Need help? Post your question and get tips & solutions from a community of 446,389 IT Pros & Developers. It's quick & easy.

K&R bitwise operator section

 P: n/a I am reading K&R and right now in section 2.9 bitwise operators. I understood most of the simple things initially but getting stuck with the later part where different functions like getbits(), setbits are explained. Is there a better guide to understand such bit operator problems with some examples. Thanks Feb 25 '07 #1
8 Replies

 P: n/a DanielJohnson wrote: I am reading K&R and right now in section 2.9 bitwise operators. I understood most of the simple things initially but getting stuck with the later part where different functions like getbits(), setbits are explained. Is there a better guide to understand such bit operator problems with some examples. Thanks A quick Google search turns up these links: What specifically do you not understand? Feb 25 '07 #2

 P: n/a What specifically do you not understand? I was trying to solve the exercises 2.6-2.8 and could not get the results. Then I googled searched for solutions and found couple of programs for it but I could not get the logic and wanted more English explanation for what is being done there. Feb 25 '07 #3

 P: n/a DanielJohnson wrote: What specifically do you not understand? I was trying to solve the exercises 2.6-2.8 and could not get the results. Then I googled searched for solutions and found couple of programs for it but I could not get the logic and wanted more English explanation for what is being done there. Well, firstly get a copy of The C Answer Book (2nd Ed.) by Clovis L. Tondo and Scott E. Gimpel. It has solutions to all the Exercises in K&R2. Also the clc wiki (http://clc-wiki.net/) has some solutions as well. Feb 25 '07 #4

 P: n/a DanielJohnson wrote: What specifically do you not understand? I was trying to solve the exercises 2.6-2.8 and could not get the results. Then I googled searched for solutions and found couple of programs for it but I could not get the logic and wanted more English explanation for what is being done there. These are the solutions from the clc wiki. Don't consult them before giving your best try at the problems. Feb 25 '07 #5

 P: n/a On Feb 25, 12:47 pm, "santosh"

 P: n/a In article <11**********************@j27g2000cwj.googlegroups .com>, DanielJohnson One quick question with bit operators. How can we print a number inbinary. For example 10 should print as 00001010. There's no printf() functionality to do it, but you can roll your own: http://c-faq.com/misc/hexio.html -Beej Feb 25 '07 #7

 P: n/a santosh wrote: DanielJohnson wrote: What specifically do you not understand? I was trying to solve the exercises 2.6-2.8 and could not get theresults. Then I googled searched for solutions and found couple ofprograms for it but I could not get the logic and wanted more Englishexplanation for what is being done there. Well, firstly get a copy of The C Answer Book (2nd Ed.) by Clovis L. Tondo and Scott E. Gimpel. It has solutions to all the Exercises in K&R2. Also the clc wiki (http://clc-wiki.net/) has some solutions as well. Not before you have given your best shot :-). Otherwise there is no point solving the problems just by looking at solutions. Tejas Kokje Feb 26 '07 #8

 P: n/a DanielJohnson wrote: > .... snip ... > One quick question with bit operators. How can we print a number in binary. For example 10 should print as 00001010. Since it is possible to write octal and hex notations I was wondering if there is anything that supports printing of binary. Try the following: /* Routines to display values in various bases */ /* with some useful helper routines. */ /* by C.B. Falconer, 19 Sept. 2001 */ /* Released to public domain. Attribution appreciated */ #include #include #include Feb 26 '07 #9