Monday, 28 April 2014

Differential coding

#include<stdio.h>
#include<conio.h>
int main()
{
    int n,num,i,regester=0,ascii[20],encoding[20],bitrequired,reducedbit=0;
    char str[20];
    printf("enter the size of characters\n");
    scanf("%d",&n);
    bitrequired=7*n;
    printf("enter %d characters\n",n);
    for(i=0;i<n;i++)
    scanf("%s",&str[i]);
    for(i=0;i<n;i++)
    {
                    num=str[i];
                    ascii[i]=num;
    }
    for(i=0;i<n;i++)
    {
                    encoding[i]=ascii[i]-regester;
                    regester=ascii[i];
    }
    printf("encoded numbers are\n\n");
    for(i=0;i<n;i++)
    {
            printf("%d\t",encoding[i]); 
            num=encoding[i];
            if(num<=127 && num>63)
            reducedbit=reducedbit+7;
            else if(num<=63 && num>31)
            reducedbit=reducedbit+6;
             else if(num<=31 && num>15)
            reducedbit=reducedbit+5;
             else if(num<=15 && num>7)
            reducedbit=reducedbit+4;
             else if(num<=7 && num>3)
            reducedbit=reducedbit+3;
             else if(num<=3 && num>1)
            reducedbit=reducedbit+2;
            else
            reducedbit++;       
              
    }
    printf("required bit=%d\n",bitrequired);
    printf("reduced bit = %d",reducedbit);
    getch();

}

No comments:
Write comments

Featured post

List of Universities in Karnataka offering M.Sc Computer Science

The post-graduate programme in Computer Science (M.Sc Computer Science) contains two academic years duration and having a four semesters....

Popular Posts

Copyright @ 2011-2016