Re: bit/byte processing in cocoa
Re: bit/byte processing in cocoa
- Subject: Re: bit/byte processing in cocoa
- From: Shawn Erickson <email@hidden>
- Date: Thu, 13 Jan 2005 09:09:00 -0800
On Jan 13, 2005, at 8:58 AM, Bob Ippolito wrote:
On Jan 13, 2005, at 4:28, Shawn Erickson wrote:
On Jan 12, 2005, at 10:07 PM, Jon wrote:
I was wondering how to deal with bits/bytes in cocoa. How could I,
say AND a char with another? Or XOR it, or use other things like
shr/shl etc? Sorry for the newbie question, but I can't figure it
out.
How you do it in C? Objective-C is a super set of C so anything you
can do in C you can do in Objective-C.
(of course I am assuming you the C programming language)
I personally have no idea what "shr" or "shl" is nor much idea
exactly what you are trying to do and how you are having problems
with it (what of Cocoa are you using, etc.) so providing more
information would be helpful.
shr and shl are (x86?) assembly mnemonics for shifting bits right and
left respectively.
Ah now I know why I have heard of them but not what they did... of
course PPC has different instructions and hence...
use regular 'ol C syntax.
As an example just in case you don't know C (get a book on it as
needed)...
char inByte = 0xA5, outByte, mask = 0x0F;
outByte = inByte << 2; //shift it left two bits
outByte = inByte >> 5; //shift it right five bits (and sign extend)
outByte = inByte & mask; // bitwise and
outByte = inByte | mask; // bitwise or
outByte = inByte ^ mask; // bitwise xor
Also if you had some thing like...
outByte = outByte & mask;
...you could shorten it to...
outByte &= mask;
-Shawn
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden