Skip to content
Snippets Groups Projects
Commit eb4f080f authored by 이소현's avatar 이소현
Browse files

lec11

parent bedac182
No related branches found
No related tags found
No related merge requests found
#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);
}
#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);
}
}
#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);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment