Solved

bitwise operations

Posted on 1999-01-21
2
228 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

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!

Question has a verified solution.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

617 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