// Dreizeiler.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include #include #include void xxx(int idx) { printf("%d Ergebnis%s\n", idx, idx==1?" ":"se"); } // http://www.wisc-online.com/ViewObject.aspx?ID=IAU8307 /* The purpose of this function is to convert an unsigned binary number to reflected binary Gray code. Binary 1-x-0-x-1-x-0-x-1 | ` ` ` ` | | | | | x = xor v v v v v Abarbeitung MSB ... LSB Gray 1 1 0 0 1 */ unsigned short BinaryToGray(unsigned short num) { return (num>>1) ^ num; } /* A tricky Trick: for up to 2^n bits, you can convert Gray to binary by performing (2^n) - 1 binary-to Gray conversions. All you need is the function above and a 'for' loop. */ unsigned short GrayToBinary(unsigned short num) { int i; unsigned short temp = num; for (i=0; i<15; i++) temp = BinaryToGray(temp); return temp; } /* Gray 1 0 1 0 1 | / / / / | x x x x x = xor v/ `v/ `v/ `v/ `v Abarbeitung MSB ... LSB Binary 1 1 0 0 1 */ unsigned short GrayToBinaryX(unsigned short num) { int i; unsigned short temp = num; temp &= 0x8000; for (i=14; i>=0; i--) { if ( (!!(temp&(1<<(i+1)))) != (!!(num&(1<>8); temp ^= (temp>>4); temp ^= (temp>>2); temp ^= (temp>>1); return temp; } #define xor ^ #define a 0x15 #define b 'b' #define MAX(a,b) (((a) < (b)) ? (b) : (a)) int main(int argc, char* argv[]) { int dir, enable=1, endschalter=0, right=0, left=1; dir = enable?endschalter?0:right^left?right?1:2:0:0; char Array[6]={'1','2','.','1','2',0}; float XValue = atof(Array); // Peakmeter // M = Mittelwert // N = neuer Messwert // A = Abklingzeit: Wert kleiner-->schneller float M=0, N=0, A=8; for (int loop=0; loop<1000; loop++) { if(loop%77) N = 5.0; else N = 100.0; M = MAX(N, (N + (A-1) * M-1)/A); printf("%f, %f\n", N, M); } int Array[9]; for (int val=123456789; val<=987654321; val++) { if(loop%77) N = 5.0; else N = 100.0; M = MAX(N, (N + (A-1) * M-1)/A); printf("%f, %f\n", N, M); } float var1 = 1.2345; float var2; var2 = (int)var1; int aa,bb; aa = -5; bb = -2; printf("%d mod %d = %d", aa,bb,aa%bb); int gray,binary,i; char buffer[100], c; int mph = 123; char feld[12]; sprintf(feld,"%4u",mph); float flt; printf("sizeof(float)=%d\n", sizeof(flt)); double dbl; printf("sizeof(double)=%d\n", sizeof(dbl)); char t1[] = { "Hallo" " " "\"Welt\"" }; printf("%s\n", t1); char t2[] = { "Hallo"" ""Welt" }; printf("%s\n", t2); char t3[] = { "Hallo" " " "Welt" }; printf("%s\n", t3); char t4[] = { "\x48""allo"" ""Welt" }; printf("%s\n", t4); char t5[] = { "\110""allo"" ""Welt" }; printf("%s\n", t5); char t6[] = { "\110allo"" ""Welt" }; printf("%s\n", t6); char t7[] = { "\60\61""2""\x33""4" }; // = "01234" printf("%s\n", t7); int w = -7; int x = w/2; printf("\n-7/2 = %d\n", x); w = -7; x = w>>1; printf("\n-7>>1 = %d\n", x); unsigned value = 6; int centivolt, volt; for (int spannung=0; spannung<9999; spannung+=177) { centivolt = spannung%100; volt = spannung/100; printf("Spannung: %2d.%02d\n", volt, centivolt); } printf("%c %c %c %c \n", a, 'a', b, 'b'); c=getchar(); printf("Binär ----> Gray ----> Binär\n", buffer); for (i=0; i<32; i++) { itoa(i+0x100,buffer,2); // Trick für führende Nullen printf("%6s = ", buffer+1); gray = BinaryToGray(i); itoa(gray+0x100,buffer,2); printf("%6s = ", buffer+1); binary = GrayToBinary(gray); itoa(binary+0x100,buffer,2); printf("%6s \n", buffer+1); } c=getchar(); }