Solved

# bitwise operations

Posted on 1999-01-21
211 Views
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
Question by:p1

LVL 4

Expert Comment

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

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

Question has a verified solution.

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