1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

bit manipulation

Discussion in 'C' started by answerme, Apr 20, 2010.

  1. answerme

    answerme New Member

    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
     
  2. virxen

    virxen New Member

    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;
    }
    
    
     

Share This Page