Monday, August 1, 2016

Published August 01, 2016 by with 0 comment

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

#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;
}
      edit

0 comments:

Post a Comment