Re: How useful are bit operators?
Re: How useful are bit operators?
- Subject: Re: How useful are bit operators?
- From: Alastair Houghton <email@hidden>
- Date: Wed, 25 Jul 2007 00:11:18 +0100
On 24 Jul 2007, at 21:11, Bob Ueland wrote:
In Kochan's book "Programming in Objective-C", four pages are
devoted to bit operators like, Bitwise AND, Bitwise OR, Left shift
and so on. How useful are those operations in Cocoa programming?
Could you give me an example where you actually was forced to use
a bit operation.
The most obvious example is working with bitmap data (consider, for
instance, an image encoded in RGB565, or a monochrome image), but
there are plenty of others.
Some of my favourite algorithms are based on bitwise operations. A
good implementation of strlen(), for instance, can search for the NUL
an entire machine word at a time, which is much faster than a naïve
implementation. And you can do neat tricks like quickly reversing
the bits (or bytes) in a word, counting the number of set bits, or
finding the highest set bit (both of which have some good real-world
applications) using bitwise operations.
There's a nice list of useful "bit-twiddling" tricks here:
http://graphics.stanford.edu/~seander/bithacks.html
though personally I like the intellectual challenge of coming up with
my own solutions :-)
All of this is really about C rather than Cocoa per se; you have to
remember that ObjC is just C with a few small extensions, so all the
things that are useful for C programmers are still useful for Cocoa
programmers.
Kind regards,
Alastair.
--
http://alastairs-place.net
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden