First import of end-test
authorHansjürg Wenger <hansjuerg.wenger@bfh.ch>
Wed, 3 Oct 2012 12:22:19 +0000 (12:22 +0000)
committerHansjürg Wenger <hansjuerg.wenger@bfh.ch>
Wed, 3 Oct 2012 12:22:19 +0000 (12:22 +0000)
ntest [new file with mode: 0755]
ntest.c [new file with mode: 0644]
ntest.lost [new file with mode: 0755]

diff --git a/ntest b/ntest
new file mode 100755 (executable)
index 0000000..2080e7f
Binary files /dev/null and b/ntest differ
diff --git a/ntest.c b/ntest.c
new file mode 100644 (file)
index 0000000..8b232c9
--- /dev/null
+++ b/ntest.c
@@ -0,0 +1,43 @@
+//
+// silly program to demonstrate endianness of a system
+//
+// (c) BFH, WGH1
+//
+#include <stdio.h>
+#include <unistd.h>
+
+void main (void){
+
+       int tv=439041101;       // test variable "tv" 
+       int so;                 // size of (tv)
+       int i;                  // used for iteration
+       unsigned char *b;       // a pointer to a byte
+
+
+       printf ("\n");
+
+// print tv decimal and hex
+       printf ("Wert von tv, dec: %i hex: %X\n",tv,tv);
+
+// assign the size (in bytes) of "tv" to "so" and print it
+       so=sizeof(tv);
+       printf ("Anzahl belegte Bytes von tv: %i\n",so);
+
+// assign the address of tv (pointer to int) to b (pointer to byte)
+// the cast makes the conversion to prevent from compiler warnings
+       b=(unsigned char *)&tv;
+       printf ("Basisadresse tv: %p = Basisadresse b: %p\n", &tv,b);
+
+       printf ("\n");
+
+// read and print bytes of "tv", "high end" first
+       for(i=3;i>=0;i--)
+       {
+               printf ("Byte %i: ",i);
+               printf ("%p: ",(b+i));
+               printf ("%X\n",*(b+i));
+       }
+
+       printf ("\n");
+
+}
diff --git a/ntest.lost b/ntest.lost
new file mode 100755 (executable)
index 0000000..5344fb9
Binary files /dev/null and b/ntest.lost differ