diff --git a/CallbyAddressAndCallbyValue.c b/CallbyAddressAndCallbyValue.c new file mode 100644 index 0000000000000000000000000000000000000000..60edc780291595f4d68cd37c0a34fbdbc7cf0c6b --- /dev/null +++ b/CallbyAddressAndCallbyValue.c @@ -0,0 +1,39 @@ +#include <stdio.h> + +void addPointer(int *a, int *b, int *c) +{ + *c = *a + *b; + fprintf(stdout, "In addPointer A %d : %lld %llx\n", *a, a, a); + fprintf(stdout, "In addPointer B %d : %lld %llx\n", *b, b, b); + fprintf(stdout, "In addPointer C %d : %lld %llx\n", *c, c, c); + *a = -100; + *b = -200; +} + +int addValue(int a, int b, int c) +{ + c = a + b; + fprintf(stdout, "In addValue A %d : %lld %llx\n", a, &a, &a); + fprintf(stdout, "In addValue B %d : %lld %llx\n", b, &b, &b); + fprintf(stdout, "In addValue C %d : %lld %llx\n", c, &c, &c); + a = 999; b=888; + return c; +} + +int main() +{ + int a = 100; + int b = 200; + int c = 999; + + fprintf(stdout, "%d : %lld %llx\n", a, &a, &a); + fprintf(stdout, "%d : %lld %llx\n", b, &b, &b); + addPointer(&a,&b,&c); + fprintf(stdout, "%d : %lld %llx\n", c, &c, &c); + // a = 200; b = 300; + c = addValue(a,b,c); + fprintf(stdout, "%d : %lld %llx\n", a, &a, &a); + fprintf(stdout, "%d : %lld %llx\n", b, &b, &b); + fprintf(stdout, "%d : %lld %llx\n", c, &c, &c); +} + diff --git a/lec10/test3.c b/lec10/test3.c new file mode 100644 index 0000000000000000000000000000000000000000..5a4e7b1dcbf0d3acd6929588c756c2f9242fa773 --- /dev/null +++ b/lec10/test3.c @@ -0,0 +1,24 @@ +#include <stdio.h> + +int fxMul1(int a, int b) +{ + return a*b; +} + +int fxMul2(int a, int b) +{ + return (int)((long long) a * (long long) b) ; +} + +int main() +{ + int i=0; + int ia, ib, ic, ic2; + float fa; + // fscanf(stdin, "%d %d", &ia, &ib); + for ( i = 0; i < 64*256*256*256; i+=(5)) + { + ic = fxMul1(i, i); + ic = fxMul2(i, i); + } +} diff --git a/lec11/rgba.c b/lec11/rgba.c new file mode 100644 index 0000000000000000000000000000000000000000..6734acfafd58096f4df49f0c6b8120683368ba27 --- /dev/null +++ b/lec11/rgba.c @@ -0,0 +1,65 @@ +#include <stdio.h> + +typedef unsigned int t_rgba; +#define fromRGBA(r,g,b,a) ((((r)&0xff)<<24)|(((g)&0xff)<<16)|(((b)&0xff)<<8)|((a)&0xff)); + +#define F_NUM_1_255 (1.0f/255.0f) +t_rgba mul_float(t_rgba c1, t_rgba c2) +{ + float r1,g1,b1,a1; + float r2,g2,b2,a2; + int ir,ig,ib,ia; + r1 = (float) ((c1 >> 24) ) * F_NUM_1_255; + g1 = (float) ((c1 >> 16) & 0xff) * F_NUM_1_255; + b1 = (float) ((c1 >> 8) & 0xff) * F_NUM_1_255; + a1 = (float) ((c1 ) & 0xff) * F_NUM_1_255; + + r2 = (float) ((c2 >> 24) ) * F_NUM_1_255; + g2 = (float) ((c2 >> 16) & 0xff) * F_NUM_1_255; + b2 = (float) ((c2 >> 8) & 0xff) * F_NUM_1_255; + a2 = (float) ((c2 ) & 0xff) * F_NUM_1_255; + + ir = (int) ((r1 * r2) * 255.0f); + ig = (int) ((g1 * g2) * 255.0f); + ib = (int) ((b1 * b2) * 255.0f); + ia = (int) ((a1 * a2) * 255.0f); + + return fromRGBA(ir,ig,ib,ia); +} + +t_rgba mul_int(t_rgba c1, t_rgba c2) +{ + unsigned int r1,g1,b1,a1; + unsigned int r2,g2,b2,a2; + int r,g,b,a; + r1 = c1 >> 24 ; r2 = c2 >> 24; + g1 = (c1 >> 16) & 0xff ; g2 = (c2 >> 16) & 0xff; + b1 = (c1 >> 8) & 0xff ; b2 = (c2 >> 8) & 0xff; + a1 = c1 & 0xff ; a2 = c2 & 0xff; + r = (r1*r2) >> 8; + g = (g1*g2) >> 8; + b = (b1*b2) >> 8; + a = (a1*a2) >> 8; + return fromRGBA(r,g,b,a); +} + +//unsigned int fromRGBA(int r, int g, int b, int a) +//{ + // return r*256*256*256 + g*256*256 + b*256 + a; + //return ((r<<24) + (g<<16) + (b<<8) + a); +// return (((r&0xff)<<24) | ((g&0xff)<<16) | ((b&0xff)<<8) | (a&0xff)); +//} + +int main() +{ + int red, green, blue, alpha; + t_rgba rgba_1, rgba_2; + // input value must be in 0~255 : 0.0 ~ 1.0 으로 해석 + // rgba_1 [rrrrrrrr][gggggggg][bbbbbbbb][aaaaaaaa] + printf("Input 4 values with 0~255 "); + scanf("%d %d %d %d", &red, &green, &blue, &alpha); + rgba_1 = fromRGBA(red, green, blue, alpha); + printf("%d %d %d %d : %u 0x%8x\n", red,green,blue,alpha,rgba_1,rgba_1); + rgba_2 = mul_float(rgba_1, rgba_1); + printf("%d %d %d %d : %u 0x%8x\n", red,green,blue,alpha,rgba_2,rgba_2); +}