bit manipulation

answerme's Avatar, Join Date: Dec 2007
Ambitious contributor
I have 13 bytes of data which i need to parse
First 5 bytes are char
next 2 bytes are int
next 3 bytes are char
nxt 1 bye is char
remaining 2 byte is int

How should i do bit manipulation
virxen's Avatar, Join Date: Nov 2009
Pro contributor
one way is this
Code:
#include <stdio.h>
#include <stdlib.h>

int main(){
    int i;
    char bytes[14]="ABCDE12ABC%56";
    char b1[6]="";
    char b2[3]="";int b2i;
    char b3[4]="";
    char b4;
    char b5[3]="";int b5i;
        for (i=0;i<5;i++){//5 chars
           b1[i]=bytes[i];
        }
        for (i=5;i<7;i++){//integer
           b2[i-5]=bytes[i];
        }
        b2i=atoi(b2);
         for (i=7;i<10;i++){//3 chars
            b3[i-7]=bytes[i];
         }
         b4=bytes[10];//char
         for (i=11;i<13;i++){//integer
            b5[i-11]=bytes[i];
         }
         b5i=atoi(b5);
    printf("\n string before parsing=<%s>",bytes);
    printf("\n first=<%s>",b1);
    printf("\n second=<%d>",b2i);
    printf("\n third=<%s>",b3);
    printf("\n fourth=<%c>",b4);
    printf("\n fifth=<%d>",b5i);
    getchar();
    return 0;
}