shift and concatenate char *

M

Martin Andersson

Hi

-------------------------------------------------------------
typedef struct bitarray {
unsigned short length; /* number of significant bits */
unsigned char *value;
} bitarray;

bitarray V1,V2;
char *V1V2;
-------------------------------------------------------------

unsigned char *value should represent a binary vector (or what
it might be called).

If I now like to concatenate V1.value and V2.value how
to do so. If the number of significant bits of V1.value don't
have an multiple of 8bits.I must start to shift and keep track of the bits.
So I was hoping that any one has some good example how to accomplish this.

Example
bits byte position
V1.value ---> 01010101 [0]
01010101 [1]
01010 [2]
V2.value ---> 10101010 [0]
0101010 [1]

V1V2 ---> 01010101 [0]
01010101 [1]
01010101 [2]
01010010 [3]
1010 [4]
 
A

Alex Fraser

Martin Andersson said:
typedef struct bitarray {
unsigned short length; /* number of significant bits */
unsigned char *value;
} bitarray;

bitarray V1,V2;
char *V1V2;

Should this be:
unsigned char *V1V2;
Or perhaps:
bitarray V1V2;
?
-------------------------------------------------------------

unsigned char *value should represent a binary vector (or what
it might be called).

If I now like to concatenate V1.value and V2.value how
to do so. If the number of significant bits of V1.value don't
have an multiple of 8bits.I must start to shift and keep track of the
bits. So I was hoping that any one has some good example how to
accomplish this.

There are lots of ways to do it. The simplest is one bit at a time. This is
very likely not the most efficient method, but there is no point worrying
about that until/unless the (lack of) efficiency is identified as a problem.

Alex
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top