Created
February 3, 2014 12:02
-
-
Save mateusza/8782730 to your computer and use it in GitHub Desktop.
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
#include <stdio.h> | |
typedef struct pair_struct { | |
unsigned short a; | |
unsigned short b; | |
} pair; | |
unsigned int swap( unsigned int ); | |
pair procedure( pair, unsigned short ); | |
void show_pair( pair ); | |
pair procedure( X, c ) | |
pair X; | |
unsigned short c; | |
{ | |
pair Y; | |
Y.a = X.b ^ c; | |
Y.b = swap( X.a + c ); | |
return Y; | |
} | |
unsigned int swap( a ) | |
unsigned int a; | |
{ | |
return ( ( a & 0xff00 ) >> 8 ) | ( ( a & 0x00ff ) << 8 ); | |
} | |
void show_pair( X ) | |
pair X; | |
{ | |
printf( "[%04x:%04x]\n", X.a, X.b ); | |
} | |
void show_pair_dec( X ) | |
pair X; | |
{ | |
printf( "[%d:%d]\n", (int) X.a, (int) X.b ); | |
} | |
int main(){ | |
pair X = { .a = 0, .b = 0 }; | |
show_pair( X ); | |
X = procedure( X, 9402 ); | |
show_pair( X ); | |
X = procedure( X, 3453 ); | |
show_pair( X ); | |
X = procedure( X, 1324 ); | |
show_pair( X ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment