Help me to work with 10bits data

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kikkubey
    New Member
    • Oct 2008
    • 2

    Help me to work with 10bits data

    Dear all,

    I have 4 numbers (A[0-3]) stored 10 bits data. the first 8 bits data stored in 1 byte data arrays (B[0-3]). the last 2bits of each A[i] stored sequentially in 1 byte number C (the first two bits of C is the last 2 bits of A[0]). Could you please help me to restore A array from B and C data in C-language?

    short A[4]; // unsigned
    unsigned char B[4];
    unsigned char C;

    how to set first 6bits of A[0] to zero? and then set the next 8bits of A[0] following to B[0]; and then set the last 2bits of A[0] to the first 2bits of C

    Thank you very much,

    kik
  • donbock
    Recognized Expert Top Contributor
    • Mar 2008
    • 2427

    #2
    Originally posted by kikkubey
    I have 4 numbers (A[0-3]) stored 10 bits data. the first 8 bits data stored in 1 byte data arrays (B[0-3]). the last 2bits of each A[i] stored sequentially in 1 byte number C (the first two bits of C is the last 2 bits of A[0]). Could you please help me to restore A array from B and C data in C-language?

    short A[4]; // unsigned
    unsigned char B[4];
    unsigned char C;
    In what follows, "cat" refers to a bit-concatenation operation. Have I correctly restated your requirements?
    ... A[0] = B[0] cat (first two bits of C);
    ... A[1] = B[1] cat (second two bits of C);
    ... A[2] = B[2] cat (third two bits of C);
    ... A[3] = B[3] cat (last two bits of C);
    I assume "the first two bits" are the two most-significant bits.

    If so, then you have two basic tasks:
    1. Extract the proper two bits from C.
    2. Perform the bit-concatenation operation.

    Do you have any ideas for how to perform these tasks in C/C++?

    Comment

    • kikkubey
      New Member
      • Oct 2008
      • 2

      #3
      Originally posted by donbock
      In what follows, "cat" refers to a bit-concatenation operation. Have I correctly restated your requirements?
      ... A[0] = B[0] cat (first two bits of C);
      ... A[1] = B[1] cat (second two bits of C);
      ... A[2] = B[2] cat (third two bits of C);
      ... A[3] = B[3] cat (last two bits of C);
      I assume "the first two bits" are the two most-significant bits.

      If so, then you have two basic tasks:
      1. Extract the proper two bits from C.
      2. Perform the bit-concatenation operation.

      Do you have any ideas for how to perform these tasks in C/C++?
      yes, thank you for making my question more clear,

      Comment

      Working...