• Status: Solved
• Priority: Medium
• Security: Public
• Views: 240

# 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
1 Solution

Commented:
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

Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.