Archive for the 'Fun' Category

21
Jan
09

back to teaching again

picture-1I left my favorite session of coding and debugging today, because I was so excited being a teacher again!

So let me pending the technical report about my research until tomorrow ;)

07
Dec
08

My Research Analogy

I have posted some thoughts about my research to my less-strict and less-formal personality blogs here and here.

Enjoy ;)

04
Nov
08

Zoom in, zoom out!

Done the presentation at Math Dept. today. It was so great! We had a long and interesting discussion, both from engineering and mathematical point of view.

We found lot of things to explore, agreed on some assumptions and also did some calculations. It was super fun!

Well I guess my mistake here was that I did to much zoom in, where I supposed to do zoom out. The zoom in works on today’s presentation, but certainly not for yesterday’s class.

Oh well. At least I learned something about zooming in and zooming out :D

27
Oct
08

Arithmetic/logical shift?

Have just learned from the previous posting that:

  1. Arithmetic/logical shift is determined by the datatype.
  2. Use the max bitlength o test the behaviour of shift operation in certain datatypes (in this case 32 bits for int).
24
Oct
08

About sign extending

The examples below show the problem in sign extending:

And this is the code:

// Code for sign extending
// CG – 24102008

#include <stdio.h>

void int_to_bin(unsigned x){
unsigned char b[32];
unsigned char i;

for (i=0; i<32; i++){
b[i] = 0;
}

i = 31;
while (x > 0){
b[i] = x % 2;
x = x / 2;
i–;
}

for (i=0; i<32; i++){
printf(“%d”, b[i]);
if ( ( ( i+1 ) % 8 ) == 0 ){
printf(” “);
}
}
}

typedef unsigned packed_t;

//this is the wrong implementation
int xbyteincorrect(packed_t word, int bytenum){
return (word >> (bytenum << 3)) & 0xFF;
}

//this is the correct implementation with sign extending
int xbytecorrect(packed_t word, int bytenum){
return (((word<<((3-bytenum)<<3))>>24)-(((word<<((3-bytenum)<<3))>>31)<<8));
}

int main () {
int x, y;

printf(“Enter an integer: “);
scanf(“%d”, &x);
printf(“Enter byte number: “);
scanf(“%d”, &y);

printf(“\nword \t\t\t\t\t\t\t\t\t\t\t\t\t\t:\t”);
int_to_bin(x);

printf(“\n\nThe incorrect result: “);
printf(“\n——————– “);
printf(“\nbytenum \t\t\t\t\t\t\t\t\t\t\t\t:\t%d”, y);
printf(“\nbytenum \t\t\t\t\t\t\t\t\t\t\t\t:\t”);
int_to_bin(y);
printf(“\nbytenum<<3 \t\t\t\t\t\t\t\t\t\t\t:\t%d”, y<<3);
printf(“\nbytenum<<3 \t\t\t\t\t\t\t\t\t\t\t:\t”);
int_to_bin((y)<<3);
printf(“\nword>>(bytenum<<3) \t\t\t\t\t\t\t\t:\t0x%x”, x>>(y<<3));
printf(“\nword>>(bytenum<<3) \t\t\t\t\t\t\t\t:\t”);
int_to_bin(x>>(y<<3));
printf(“\n0xFF \t\t\t\t\t\t\t\t\t\t\t\t\t\t:\t0x%x”, 0xFF);
printf(“\n0xFF \t\t\t\t\t\t\t\t\t\t\t\t\t\t:\t”);
int_to_bin(0xFF);
printf(“\n((word>>(bytenum<<3)) & 0xFF \t\t\t\t:\t0x%x”, (x>>(y<<3))&0xFF);
printf(“\n((word>>(bytenum<<3)) & 0xFF \t\t\t\t:\t”);
int_to_bin((x>>(y<<3))&0xFF);
printf(“\nIncorrect result \t\t\t\t\t\t\t\t\t:\t0x%x\n”, xbyteincorrect(x, y));

printf(“\n\nThe correct result: “);
printf(“\n—————— “);
printf(“\nbytenum \t\t\t\t\t\t\t\t\t\t\t\t:\t%d”, y);
printf(“\nbytenum \t\t\t\t\t\t\t\t\t\t\t\t:\t”);
int_to_bin(y);
printf(“\n3-bytenum \t\t\t\t\t\t\t\t\t\t\t\t:\t%d”, 3-y);
printf(“\n3-bytenum \t\t\t\t\t\t\t\t\t\t\t\t:\t”);
int_to_bin(3-y);
printf(“\n(3-bytenum)<<3 \t\t\t\t\t\t\t\t\t\t:\t%d”, (3-y)<<3);
printf(“\n(3-bytenum)<<3 \t\t\t\t\t\t\t\t\t\t:\t”);
int_to_bin((3-y)<<3);
printf(“\nword<<((3-bytenum)<<3) \t\t\t\t\t\t\t:\t0x%x”, x<<((3-y)<<3));
printf(“\nword<<((3-bytenum)<<3) \t\t\t\t\t\t\t:\t”);
int_to_bin(x<<((3-y)<<3));
printf(“\n(((word<<((3-bytenum)<<3))>>24)  \t\t\t:\t0x%x”, (x<<((3-y)<<3))>>24);
printf(“\n(((word<<((3-bytenum)<<3))>>24)  \t\t\t:\t”);
int_to_bin((x<<((3-y)<<3))>>24);
printf(“\n(((word<<((3-bytenum)<<3))>>31)  \t\t\t:\t0x%x”, (x<<((3-y)<<3))>>31);
printf(“\n(((word<<((3-bytenum)<<3))>>31)  \t\t\t:\t”);
int_to_bin((x<<((3-y)<<3))>>31);
printf(“\n((((word<<((3-bytenum)<<3))>>31)<<8) \t:\t0x%x”, ((x<<((3-y)<<3))>>31)<<8);
printf(“\n((((word<<((3-bytenum)<<3))>>31)<<8) \t:\t”);
int_to_bin(((x<<((3-y)<<3))>>31)<<8);
printf(“\n(((word<<((3-bytenum)<<3))>>24)-(((word<<((3-bytenum)<<3))>>31)<<8)) \t:\t0x%x”, (((x<<((3-y)<<3))>>24)-(((x<<((3-y)<<3))>>31)<<8)));
printf(“\n(((word<<((3-bytenum)<<3))>>24)-(((word<<((3-bytenum)<<3))>>31)<<8)) \t:\t”);
int_to_bin((((x<<((3-y)<<3))>>24)-(((x<<((3-y)<<3))>>31)<<8)));
printf(“\nCorrect result \t\t\t\t\t\t\t\t\t\t:\t0x%x\n”, xbytecorrect(x, y));

getchar();
return 0;
}

20
Oct
08

Congrats for a new Phd!

Hey hey, my PhD fellow had successfully defend his thesis last Saturday!

More about it here. And maybe here.

13
Oct
08

When papers and pen are so useful :)

Spending the day without computers, feels like I’m half of me, but to be honest it’s not that bad :D

Tonight I got back “my half” and start to pick up where I left :)


13
Oct
08

Math Department

I made a visit to the math department this morning to meet my supervisor/advisor/partner/bestfriend Intan. I had been struggling finding answers to my questions (check my previous postings :) ) , and then had a thought that asking for a help from a mathematician would solve my problems right away ;)

So it was a great morning, discussing about those interesting math details, and got my brain boosted. A visit to math department always gives a charging effect for me!

Now I understand and can answer the questions from my previous postings!

Thanks mathematician(s)!!! ;)

01
Aug
08

Advanced vs Beginner

Well, seems like I picked the right supervisor/advisor. He’s still a good programmer! Here’s what we did yesterday. Oh, it was fun learning from the expert!

20
Jul
08

Scientific Integrity – Feynman

Finally managed to finish this book. More about it here and here.




Blog Stats

  • 11,004 hits

Categories

 

November 2009
M T W T F S S
« Mar    
 1
2345678
9101112131415
16171819202122
23242526272829
30