/* =====================================================================================
* *
* * Filename: leftshift.c
* * Created: Tuesday 3 February 2015
* * Compiler: gcc
* * Author: Manoj Kumar Patra,manojpatra.sit@gmail.com
* * Organization: SCIS,University of Hyderabad
* *
* * =====================================================================================*/
#include<stdio.h>
int main()
{
int dn,rem,quo,k=0,m,sb,temp;
int binaryNumber[100],bin[100],i=1,j;
printf("------------------------------------------\n");
printf("Enter any decimal number: ");
scanf("%d",&dn);
quo = dn;
while(quo!=0)
{
binaryNumber[i++]= quo % 2;
quo = quo / 2;
}
printf("\nEquivalent binary value of decimal number %d: ",dn);
for(j = i -1 ;j> 0;j--)
{
printf("%d",binaryNumber[j]);
bin[k]=binaryNumber[j];
k++;
}
printf("\n------------------------------------------");
printf("\nHow many bits you wanna left-shift:");
scanf("%d",&sb);
for(i=0; i<sb; i++)
{
temp=bin[0];
for(m=0; m<k; m++)
{
bin[m]=bin[m+1];
}
bin[k-1]=temp;
}
printf("\nThe binary number after left-shift:");
for(m=0 ;m<k; m++)
{
printf("%d",bin[m]);
}
printf("\n------------------------------------------\n");
return 0;
}
OutPut:
* *
* * Filename: leftshift.c
* * Created: Tuesday 3 February 2015
* * Compiler: gcc
* * Author: Manoj Kumar Patra,manojpatra.sit@gmail.com
* * Organization: SCIS,University of Hyderabad
* *
* * =====================================================================================*/
#include<stdio.h>
int main()
{
int dn,rem,quo,k=0,m,sb,temp;
int binaryNumber[100],bin[100],i=1,j;
printf("------------------------------------------\n");
printf("Enter any decimal number: ");
scanf("%d",&dn);
quo = dn;
while(quo!=0)
{
binaryNumber[i++]= quo % 2;
quo = quo / 2;
}
printf("\nEquivalent binary value of decimal number %d: ",dn);
for(j = i -1 ;j> 0;j--)
{
printf("%d",binaryNumber[j]);
bin[k]=binaryNumber[j];
k++;
}
printf("\n------------------------------------------");
printf("\nHow many bits you wanna left-shift:");
scanf("%d",&sb);
for(i=0; i<sb; i++)
{
temp=bin[0];
for(m=0; m<k; m++)
{
bin[m]=bin[m+1];
}
bin[k-1]=temp;
}
printf("\nThe binary number after left-shift:");
for(m=0 ;m<k; m++)
{
printf("%d",bin[m]);
}
printf("\n------------------------------------------\n");
return 0;
}
OutPut:
No comments:
Post a Comment