Monday, August 1, 2016

UVA 594 - One Little, Two Little, Three Little Endians Solution

Unknown
#include<cstdio>
#include<bitset>

using namespace std;

long convert_endian(long x){
    bitset<32> b(x);
    long res = 0;
    for (int j=0; j<32; j++) if (b[j]) res |= 1<<(3-j/8)*8+(j%8);
    return res;
}

int main(){
    long x;
    while(scanf("%ld", &x)==1) printf("%ld converts to %ld\n",
        x, convert_endian(x));
    return 0;
}

Unknown

Studying at Shahjalal University of Science and Technology, Sylhet.

0 comments:

Post a Comment

Coprights @ 2016,