Solved

bitwise operations

Posted on 1999-01-21
2
211 Views
Last Modified: 2010-04-02
my job is to set each BIT of an array of unsigned char(8 bits), say arrayA, to the element of another array,say arrayB ie.:

(array of BITs-arrayA)
 7 6 5 4 3 2 1 0  
+-+-+-+-+-+-+-+-+ 0
+-+-+-+-+-+-+-+-+ 1
+-+-+-+-+-+-+-+-+ 2
+-+-+-+-+-+-+-+-+ 3

the 0th bit of word 0 goes to word 0 of arrayB
the 1st bit of word 0 goes to word 1 of arrayB
the 2th bit of word 0 goes to word 2 of arrayB
the 3st bit of word 0 goes to word 3 of arrayB
:
:
the 0th bit of word 1 goes to word 8 of arrayB
the 1st bit of word 1 goes to word 9 of arrayB
:
:

can anyone give me some codes for this task?
0
Comment
Question by:p1
2 Comments
 
LVL 4

Expert Comment

by:nil_dib
ID: 1184692
arrayB is a unsigned char array?

>> ....word 0 goes to word 0 of arrayB
word is 16bit!?

if you copy only the first bit to arrayB what is with the other
7 bits in arrayB (don't care?).

0
 
LVL 10

Accepted Solution

by:
rbr earned 50 total points
ID: 1184693
unsigned char A[100];
unsigned char B[100*8];
int i,j;

for (i=0;i<100;i++) {
      for (j=0;j < 8;j++) {
            if (A[i] & (1 <<j)) {
                  B[i*8+j]=1;
            } else {
                  B[i*8+j]=0;
            }
      }
}
      
0

Featured Post

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Issue accessing member variable of atomic class 16 116
C++ assignment question 7 199
IdTCPClient1->Disconnect(); not working 3 66
Beginner to Unreal Engine 4 5 80
In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question