• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Fwd: Cocoa and bit handling
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Fwd: Cocoa and bit handling


  • Subject: Fwd: Cocoa and bit handling
  • From: Jiri Volejnik <email@hidden>
  • Date: Tue, 21 Dec 2004 14:54:58 +0100

From: Jiri Volejnik <email@hidden>

Hi,
there is a lot of ways. Below is one of them in plain C (probably not the fastest one).

byte CopyOneBit(byte source, unsigned sourceBit, byte target, unsigned targetBit)
{
byte bit = ((source >> sourceBit) & 1) << targetBit;
return bit ? target | bit : target & ~bit;
}

Usage:
target = CopyOneBit(source,3,target,2);

With C++ (Objective-C++), if you use std::bitset<8> as a type of both source and target, it could be as simple as this (including optimization):

target[targetBit] = source[sourceBit];

Jirka.

21.12.2004, at 12:27, Peter Karlsson wrote:

Dear list!
I have 2 pointers declared as byte. They are called source and target.
The source pointer points to the first byte of a memory area. The target
pointer points to the first byte of another memory area.
Is there a easy way to move bits fom source byte to target byte?

Example:
Source byte maybe looks like this:
01001011
Target byte looks like this before:
00000000
Target byte looks like this after:
01000000

I want to move bit 3 of the source byte to bit 6 of the target byte. This
will repeat thousands of times in a loop. And the bit position changes
every lap. So next lap I maybe want to move source bit 2 to target bit 5
and so on...
Best regards Peter

 _______________________________________________
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

  • Prev by Date: Re: "Failed to load Main-Class manifest attribute"
  • Next by Date: Re: Cocoa and bit handling
  • Previous by thread: Re: Cocoa and bit handling
  • Next by thread: Re: "Failed to load Main-Class manifest attribute"
  • Index(es):
    • Date
    • Thread