4 ms·
Even the first one (Get maximum int value) is just plain wrong. Although int has a 32 bit size on almost all systems it is only guaranteed to have a size of 16
by deletes 13y ago
Even the first one (Get maximum int value) is just plain wrong.
Although int has a 32 bit size on almost all systems it is only guaranteed to have a size of 16 bits.
The correct way of getting the size of int is including limits.h ( <climits> ) and looking at the value INT_MAX.
- Sambdala 13y agoDo you (or anyone else) have a good source for someone who wants an introduction to bit operations?
- Jabbles 13y agohttp://graphics.stanford.edu/~seander/bithacks.html http://graphics.stanford.edu/~seander/bithacks.html Entertaining book: http://www.amazon.co.uk/Hackers-Delight-2nd-Edition-ebook/dp/B009GMUMTM/ref=sr_1_1?ie=UTF8&qid=1370694434&sr=8-1&keywords=hackers+delight http://www.amazon.co.uk/Hackers-Delight-2nd-Edition-ebook/dp... The reference: http://www.amazon.co.uk/The-Computer-Programming-Vol-Combinatorial/dp/0201038048/ref=sr_1_2?ie=UTF8&qid=1370694506&sr=8-2&keywords=knuth+4a http://www.amazon.co.uk/The-Computer-Programming-Vol-Combina... Section 7.1.3 Bitwise Tricks and Techniques
- Sambdala 13y agoThanks!
- Jabbles 13y agoIt's unclear what language that is. Could that be (well-defined) Java? Besides, it's also wrong because left shifting a signed integer "into the sign bit" is undefined.
- deletes 13y agoAuthor is apparently trying to combine multiple languages. Maybe well defined in java, definitely not in C.
- Jabbles 13y agoIn the original Chinese article, the languages were actually mentioned. And the one we're discussing is C++. (And so as you point out, wrong.) It annoys me that this kind of vacuous article is posted. It reminds me of an old rant about Perl tutorials: http://blogs.perl.org/users/mithaldu/2011/10/perl-tutorials-suck-and-cause-serious-damage.html http://blogs.perl.org/users/mithaldu/2011/10/perl-tutorials-...