Skip to content

Instantly share code, notes, and snippets.

@mateusza
Created February 3, 2014 12:02
Show Gist options
  • Save mateusza/8782730 to your computer and use it in GitHub Desktop.
Save mateusza/8782730 to your computer and use it in GitHub Desktop.
#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