Bit operations on buffers

P

PSN

Hello Group,
I have a character array of size 2;

char *pArray=(char *)malloc(10);
memset(pArray, 1, 10); // 0000000100000001

I want to apply shift operations, so as '&' and '|' operations on the
whole buffer at once. How can i do it ??

Ex: pArray & 0x01 ----> 1;
pArray >> 1 ----> 0000000010000000;

The 2 character buffer is just an example, and i wish to use buffers
of variable sizes.

Thanks a lot again for your time,

Prakash
 
I

Ian Collins

PSN said:
Hello Group,
I have a character array of size 2;

char *pArray=(char *)malloc(10);

Why are you using malloc?
memset(pArray, 1, 10); // 0000000100000001

I want to apply shift operations, so as '&' and '|' operations on the
whole buffer at once. How can i do it ??

Ex: pArray & 0x01 ----> 1;
pArray >> 1 ----> 0000000010000000;

The 2 character buffer is just an example, and i wish to use buffers
of variable sizes.
Have a look at std::bitset.
 
P

PSN

I am aware of the bitset container.
Have a look at std::bitset.

Can i dare to say, i want to reinvent the wheel and wish to know
exactly what i am doing behind the covers !!

thanks for your time again,
Prakash
 
I

Ian Collins

PSN said:
I am aware of the bitset container.


Can i dare to say, i want to reinvent the wheel and wish to know
exactly what i am doing behind the covers !!
In that case, rolling your own should prove an interesting exercise!
 

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,997
Messages
2,570,240
Members
46,828
Latest member
LauraCastr

Latest Threads

Top