By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,465 Members | 1,600 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,465 IT Pros & Developers. It's quick & easy.

shift and concatenate char *

P: n/a
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]

Nov 16 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
"Martin Andersson" <ja**************@yahoo.com> wrote in message
news:pMNef.1015$zc1.68@amstwist00...
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
Nov 16 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.