Last active
December 25, 2019 10:08
-
-
Save thinkphp/4060240566ccfe574b2ef88090243b65 to your computer and use it in GitHub Desktop.
Byte Swapping
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Author: Adrian Statescu <mergesortv@gmail.com> | |
* Description: Byte Swapping. | |
*/ | |
#include <stdio.h> | |
void __byteswapping__(void *x1, void *x2, size_t size) { | |
char *x = (char*)x1; | |
char *y = (char*)x2; | |
int i; | |
for(i = 0; i < size; ++i) { | |
size_t holder = *(x + i); | |
*(x + i) = *(y + i); | |
*(y + i) = holder; | |
} | |
} | |
int main() { | |
long int num1, | |
num2; | |
scanf("%ld %ld", &num1, &num2); | |
printf("num1 = %ld, num2 = %ld\n", num1, num2); | |
printf("After Swapping:\n"); | |
__byteswapping__(&num1, &num2, sizeof(long int)); | |
printf("num1 = %ld, num2 = %ld\n", num1, num2); | |
return(0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment