# Bit shifts in Cocoa - Mac Programming

Does anyone know how to do bit shifts in Cocoa? I have declared an integer and I want to shift it one bit to the right (same as dividing by 2). How can this be done in Cocoa? I already tried "x >> 1", but it did not recognize the ">>" syntax. I'm also interested in information about other mathematical logical syntax in Cocoa. I didn't find anything about that on the apple developer web site. Any help is appreciated. -Korbin...

1. ## Bit shifts in Cocoa

Does anyone know how to do bit shifts in Cocoa? I have declared an
integer and I want to shift it one bit to the right (same as dividing
by 2). How can this be done in Cocoa? I already tried "x >> 1", but
it did not recognize the ">>" syntax. I'm also interested in
information about other mathematical logical syntax in Cocoa. I
didn't find anything about that on the apple developer web site. Any
help is appreciated.

-Korbin
Korbin Meiser Guest

2. ## Re: Bit shifts in Cocoa

On 10 Sep 2003, Korbin Meiser wrote:
> Does anyone know how to do bit shifts in Cocoa? I have declared an
> integer and I want to shift it one bit to the right (same as dividing
> by 2). How can this be done in Cocoa? I already tried "x >> 1", but
> it did not recognize the ">>" syntax. I'm also interested in
> information about other mathematical logical syntax in Cocoa. I
> didn't find anything about that on the apple developer web site. Any
> help is appreciated.
First of all, your question as asked doesn't make sense. Cocoa is not a
programming langauge, it is an API. You probably meant Objective-C, which
is the langauge normally used with Cocoa.

Objective-C is just C with some OO stuck on. So all the basic math
operators are the same. Your "x >> 1" statement should work. If it
doesn't, it's either because you have another error, or you're not using
Objective-C.

--
"From now on, we live in a world where man has walked on the moon.
And it's not a miracle, we just decided to go." -- Jim Lovell

Mike Ash - <http://www.mikeash.com/>, <mailto:mailmikeash.com>

Michael J Ash Guest

3. ## Re: Bit shifts in Cocoa

[email]cryptofishhotmail.com[/email] (Korbin Meiser) wrote:
> Does anyone know how to do bit shifts in Cocoa? I have declared an
> integer and I want to shift it one bit to the right (same as dividing
> by 2). How can this be done in Cocoa? I already tried "x >> 1", but
> it did not recognize the ">>" syntax. I'm also interested in
> information about other mathematical logical syntax in Cocoa. I
> didn't find anything about that on the apple developer web site. Any
> help is appreciated.
It would help if you told us what programming language you're using. :-T

The languages that have Cocoa bindings that I know of include

Objective C
Java
Python
Perl
AppleScript

and there are probably just as many others. Some of them support
bit-shifts, others don't. Objective C (which is the language you'll want
to be using if you're doing anything as advanced as a bit-shift)
supports the << and >> operators just fine.

Cheers,
-- M. Uli Kusterer
[url]http://www.zathras.de[/url]
Uli Kusterer Guest

#### Posting Permissions

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