Write a C program that does the following for binary and hex

Write a C program that does the following for binary and hexa decimal numbers that performs the same as the output given below.

* Display binary and hexa decimal numbers after conversion from decimal numbers

* Exchange the outer bytes of binary and hexa decimal number

* Exchange the inner bytes of binary and hexa decimal number

* Display number of set bits in each byte

THE C PROGRAM SHOULD GIVE SAME OUTPUT AS THE PICTURE

cc DHEXA DECIMAL o p2x p 2. p2x Input number 287 454 020 Select option. display number in hexadecimal 2 exchange outer bytes 3 exchange inner bytes 4 display number of set bits in each byte exit number 0x11223344 select option. display number in hexadecimal 2 exchange outer bytes 3 exchange inner bytes display number of set bits in each byte exit number before 12233 44 number after 0x 22331 I

Solution

*/

# cc-DHEXADECIMAL-O p2X p2.c

# ./p2X

#include<stdio.h>

#include<conio.h>

void main()

{

int 287454020 ,num,*bin,*oct,bin_len,oct_len,hex_len;

char *hex,ch;

clrscr();

do

{

printf(\"\ Enter the number to be converted :\");

scanf(\"%d\",&num);

//printf(\"\ %c\ \",(char)48);

printf(\"\ \");

//binary

bin_len=binary(bin,num);

printf(\"\ Binary : \");

for(i=0;i<bin_len;i++)

nsigned char swapNibbles(unsigned char x)

{

    return ( (x & 0x0F)<<4 | (x & 0xF0)>>4 );

}

int main()

{

    unsigned char x = 100;

    printf(\"%u\", swapNibbles(x));

    return 0;

}

printf(\"%d\",bin[i]);

printf(\"\ \");

//hexadecimal

hex_len=hexadecimal(hex,num);

printf(\"\ Hexadecimal : \");

for(i=0;i<hex_len;i++)

printf(\"%c\",hex[i]);

printf(\"\ \");

      printf(\"\ Enter another number(y/n)?\");

      ch=getche();

                                getch();

}while(ch!=\'n\');

}

int binary(int *bin,int num)

{

int rem=0,i=0;

     do{

     rem=num%2;

     num=num/2;

     bin[i]=rem;

     i++;

     }while(num>0);

array_reverse_i(bin,i);

return i

{

int rem=0,i=0;

     do{

     rem=num%8;

     num=num/8;

     oct[i]=rem;

     i++;

     }while(num>0);

int hexadecimal(char *hex,int num)

{

int rem=0,i=0;

     do{

     rem=num%16;

     num=num/16;

     switch (rem)

                {

                case 10 : hex[i]=\'A\';

                                i++;

                                break;

                case 11 : hex[i]=\'B\';

                                i++;

                                break;

                case 12 : hex[i]=\'C\';

                                i++;

                                break;

                case 13 : hex[i]=\'D\';

                                i++;

                                break;

                case 14 : hex[i]=\'E\';

                                i++;

                                break;

                case 15 : hex[i]=\'F\';

                                i++;

                                break;

                default :hex[i]=(char)(rem+48);

                                i++;

     }

     }while(num>0);

array_reverse_c(hex,i);

return i;

}

array_reverse_i(int *arr,int len)

{

int i,temp;

for(i=0;i<len/2;i++)

{

   temp=arr[i];

   arr[i]=arr[len-1-i];

   arr[len-1-i]=temp;

}

return 0;

}

array_reverse_c(char *arr,int len)

{

int i;

char temp;

for(i=0;i<len/2;i++)

{

   temp=arr[i];

   arr[i]=arr[len-1-i];

   arr[len-1-i]=temp;

}

return 0;

}

/*

Write a C program that does the following for binary and hexa decimal numbers that performs the same as the output given below. * Display binary and hexa decima
Write a C program that does the following for binary and hexa decimal numbers that performs the same as the output given below. * Display binary and hexa decima
Write a C program that does the following for binary and hexa decimal numbers that performs the same as the output given below. * Display binary and hexa decima
Write a C program that does the following for binary and hexa decimal numbers that performs the same as the output given below. * Display binary and hexa decima

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site