Bit operations on buffers

Discussion in 'C++' started by PSN, Dec 16, 2007.

  1. PSN

    PSN Guest

    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
     
    PSN, Dec 16, 2007
    #1
    1. Advertising

  2. PSN

    Ian Collins Guest

    PSN wrote:
    > 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.

    --
    Ian Collins.
     
    Ian Collins, Dec 16, 2007
    #2
    1. Advertising

  3. PSN

    PSN Guest

    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 !!

    >
    > --
    > Ian Collins.


    thanks for your time again,
    Prakash
     
    PSN, Dec 16, 2007
    #3
  4. PSN

    Ian Collins Guest

    PSN wrote:
    > 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 !!
    >

    In that case, rolling your own should prove an interesting exercise!

    --
    Ian Collins.
     
    Ian Collins, Dec 16, 2007
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sanket Suryawanshi

    bit operations in Java

    Sanket Suryawanshi, Jan 23, 2004, in forum: Java
    Replies:
    3
    Views:
    7,102
    Jon A. Cruz
    Jan 23, 2004
  2. Jesus M. Salvo Jr.
    Replies:
    2
    Views:
    4,306
    robert
    Feb 11, 2006
  3. Replies:
    3
    Views:
    1,830
    Timothy Bendfelt
    Jan 19, 2007
  4. Replies:
    9
    Views:
    1,033
    Juha Nieminen
    Aug 22, 2007
  5. Jeff.M
    Replies:
    6
    Views:
    199
    Lasse Reichstein Nielsen
    May 4, 2009
Loading...

Share This Page