Solved

bitwise operations

Posted on 1999-01-21
2
189 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
Comment Utility
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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
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.

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now