Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 233
  • Last Modified:

bitwise operations

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
p1
Asked:
p1
1 Solution
 
nil_dibCommented:
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
 
rbrCommented:
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now