Monday, 16 June 2014

C++ program to swap nibble in a byte


Here is a C++ program to swap nibble in a byte


 SOURCE CODE OUTPUT
#include <iostream>
#include<conio.h>
using namespace std;
int main()
{
    short byte[8],temp;
    cout<<"Enter the binary number ";
    for(int i=0;i<8;i++)
    byte[i]=getche()-48;
    cout<<endl;
    for(int y=0;y<4;y++)
    {
        temp=byte[y];
        byte[y]=byte[y+4];
        byte[y+4]=temp;
    }
    cout<<"After swapping the nibbles ";
    for(int i=0;i<8;i++)
         cout<<byte[i];
    return 0;
}

Any questions regarding to program please write in comments.

No comments:

Post a Comment