Tuesday, October 09, 2007
Procedure to combine the 0x89ABCDEF and 0x76543210 as 0x765432EF
#include <stdlib.h>
/*
Procedure to combine the
0x89ABCDEF and 0x76543210
as 0x765432EF
*/
int main(int argc, char* argv[])
{
int x = 0x89ABCDEF;
int y = 0x76543210;
int z = (x & 0xFF) + (y & ~0xFF);
printf("%X \n",z);
system("PAUSE");
return 0;
}
--
Happy day, happy life!
Procedure to identify the machine is little endian or big endian
#include <stdlib.h>
/*
Procedure to identify the machine is
little endian or big endian
*/
// Using
// Compile it and run it on the target machine which you want to check.
typedef unsigned char* byte_pointer;
int is_little_endian()
{
int test = 0x0000FFFF;
int i;
byte_pointer p = (byte_pointer)&test;
return p[0] == 0xFF;
}
int main(int argc, char* argv[])
{
printf("Current machine is%slittle endian \n",is_little_endian()? " ":"not");
system("PAUSE");
return 0;
}
--
Happy day, happy life!
msup 微软访谈
. 专访微软测试经理Francis Zhou:软件测试的未来在哪里
. 访微软CEO鲍尔默:下一版Windows 不需要再等5年
--
Happy day, happy life!
Think it over……好好想想……
Today we have higher buildings and wider highways,but shorter temperaments and narrower points of view;
今天我们拥有了更高层的楼宇以及更宽阔的公路,但是我们的性情却更为急躁,眼光也更加狭隘;
We spend more,but enjoy less;
我们消耗的更多,享受到的却更少;
We have bigger houses,but smaller famillies;
我们的住房更大了,但我们的家庭却更小了;
We have more compromises,but less time;
我们妥协更多,时间更少;
We have more knowledge,but less judgment;
我们拥有了更多的知识,可判断力却更差了;
We have more medicines,but less health;
我们有了更多的药品,但健康状况却更不如意;
We have multiplied out possessions,but reduced out values;
我们拥有的财富倍增,但其价值却减少了;
We talk much,we love only a little,and we hate too much;
我们说的多了,爱的却少了,我们的仇恨也更多了;
We reached the Moon and came back,but we find it troublesome to cross our own street and meet our neighbors;
我们可以往返月球,但却难以迈出一步去亲近我们的左邻右舍;
We have conquered the uter space,but not our inner space;
我们可以征服外太空,却征服不了我们的内心;
We have highter income,but less morals;
我们的收入增加了,但我们的道德却少了;
These are times with more liberty,but less joy;
我们的时代更加自由了,但我们拥有的快乐时光却越来越少;
We have much more food,but less nutrition;
我们有了更多的食物,但所能得到的营养却越来越少了;
These are the days in which it takes two salaries for each home,but divorces increase;
现在每个家庭都可以有双份收入,但离婚的现象越来越多了;
These are times of finer houses,but more broken homes;
现在的住房越来越精致,但我们也有了更多破碎的家庭;
That's why I propose,that as of today;
这就是我为什么要说,让我们从今天开始;
You do not keep anything for a special occasion.because every day that you live is a SPECIAL OCCASION.
不要将你的东西为了某一个特别的时刻而预留着,因为你生活的每一天都是那么特别;
Search for knowledge,read more ,sit on your porch and admire the view without paying attention to your needs;
寻找更我的知识,多读一些书,坐在你家的前廊里,以赞美的眼光去享受眼前的风景,不要带上任何功利的想法;
Spend more time with your family and friends,eat your favorite foods,visit the places you love;
花多点时间和朋友与家人在一起,吃你爱吃的食物,去你想去的地方;
Life is a chain of moments of enjoyment;not only about survival;
生活是一串串的快乐时光;我们不仅仅是为了生存而生存;
Use your crystal goblets.Do not save your best perfume,and use it every time you feel you want it.
举起你的水晶酒杯吧。不要吝啬洒上你最好的香水,你想用的时候就享用吧!
Remove from your vocabulary phrases like"one of these days"or "someday";
从你的词汇库中移去所谓的" 有那么一天"或者 "某一天";
Let's write that letter we thought of writing "one of these days"!
曾打算"有那么一天 "去写的信,就在今天吧!
Let's tell our families and friends how much we love them;
告诉家人和朋友,我们是多么地爱他们;
Do not delay anything that adds laughter and joy to your life;
不要延迟任何可以给你的生活带来欢笑与快乐的事情;
Every day,every hour,and every minute is special;
每一天、每一小时、每一分钟都是那么特别;
And you don't know if it will be your last.
你无从知道这是否最后刻。
--
Happy day, happy life!
Intel IA32 Floating-Point Arithmetic problems with GCC
#include <stdlib.h>
double recip( int denom)
{
return 1.0 / (double)denom;
}
void do_nothing(){}
void test1( int denom)
{
double r1,r2;
int t1,t2;
r1 = recip(denom);
r2 = recip(denom);
t1 = r1 == r2;
printf("test1 t1: r1 %f %c= r2 %f\n",r1,t1 ? '=' : '!',r2);
do_nothing();
t2 = r1 == r2;
printf("test1 t2: r1 %f %c= r2 %f\n",r1,t2 ? '=' : '!',r2);
}
void test2(int denom)
{
double r1;
int t1;
r1 = recip(denom);
t1 = r1 == 1.0 /(double)denom;
printf("test2 t1: r1 %f %c= 1.0/10.0 \n",r1,t1 ? '=' : '!');
}
long double recip_l(int denom)
{
return 1.0/(long double)denom;
}
void test3(int denom)
{
long double r1,r2;
int t1, t2, t3;
r1 = recip(denom);
r2 = recip(denom);
t1 = r1 == r2;
printf("test3 t1: r1 %f %c= r2 %f\n",(double)r1,t1 ? '=' : '!',(double)r2);
do_nothing();
t2 = r1 == r2;
printf("test3 t2: r1 %f %c= r2 %f\n",(double)r1,t2 ? '=' : '!',(double)r2);
t3 = r1 == 1.0 /(long double)denom;
printf("test3 t3: r1 %f %c= 1.0/10.0 \n",(double)r1,t3 ? '=' : '!');
}
int main(int argc, char* argv[])
{
test1(10);
test2(10);
test3(10);
system("PAUSE");
return 0;
}
// Using
// Compile the code with GCC with compile parameters repectively
// a. -O2
// b. -ffloat-store
//Result running on redhat linux
//[root@localhost download]# gcc -O2 2.4.6.c
//[root@localhost download]# ./a.out
//test1 t1: r1 0.100000 != r2 0.100000
//test1 t2: r1 0.100000 == r2 0.100000
//test2 t1: r1 0.100000 == 1.0/10.0
//test3 t1: r1 0.100000 == r2 0.100000
//test3 t2: r1 0.100000 == r2 0.100000
//test3 t3: r1 0.100000 == 1.0/10.0
//sh: line 1: PAUSE: command not found
//
//
//[root@localhost download]# gcc -ffloat-store 2.4.6.c
//[ root@localhost download]# ./a.out
//test1 t1: r1 0.100000 == r2 0.100000
//test1 t2: r1 0.100000 == r2 0.100000
//test2 t1: r1 0.100000 != 1.0/10.0
//test3 t1: r1 0.100000 == r2 0.100000
//test3 t2: r1 0.100000 == r2 0.100000
//test3 t3: r1 0.100000 == 1.0/10.0
//sh: line 1: PAUSE: command not found
--
Happy day, happy life!
Monday, October 08, 2007
How to get the decimal value from the bit representation of a float value?(3)
For example: Float value is 3490593.0
Bit representation on little endian machine: 840C554A
Actual Bit representation is : 4A550C84
Bit representation: 01001010010101010000110010000100
Float interpretation: sign 1 bit, exponent 8 bits, fraction 23 bits.
Sign Exponent fraction
0 10010100 10101010000110010000100
Decimal
value 148 5573764/2^23
Use normal interpretation:
E = 148-(2^(8-1)-1)
(1 + 5573764/2^23)*(2^(148-(2^(8-1)-1)))
2^23 = 8388608;
148-(2^(8-1)-1) = 21;
(1 + 5573764/2^23) = 1. 664444446563720703125
(2^(148-(2^(8-1)-1))) = 2097152
(1 + 5573764/2^23)*(2^(148-(2^(8-1)-1))) = 1. 664444446563720703125* 2097152= 3490593
--
Happy day, happy life!
How to get the decimal value from the bit representation of a float value?(2)
For example: Float value is 54321.1
Bit representation on little endian machine: 1A315447
Actual Bit representation is : 4754311A
Bit representation: 01000111010101000011000100011010
Float interpretation: sign 1 bit, exponent 8 bits, fraction 23 bits.
Sign Exponent fraction
0 10001110 10101000011000100011010
Decimal
value 142 5517594/2^23
Use normal interpretation:
E = 142-(2^(8-1)-1)
(1 + 5517594/2^23)*(2^(142-(2^(8-1)-1)))
2^23 = 8388608;
142-(2^(8-1)-1) = 15;
(1 + 5517594/2^23) = 1. 6577484607696533203125
(2^(142-(2^(8-1)-1))) = 32768
(1 + 5517594/2^23)*(2^(142-(2^(8-1)-1))) = 1. 6577484607696533203125 * 32768= 54321.1015625
~54321.1
--
Happy day, happy life!
How to get the decimal value from the bit representation of a float value?
For example: Float value is 12345.0
Bit representation on little endian machine: 00E44046
Actual Bit representation is : 4640E400
Bit representation: 01000110010000001110010000000000
Float interpretation: sign 1 bit, exponent 8 bits, fraction 23 bits.
Sign Exponent Fraction
0 10001100 10000001110010000000000
Decimal
value 140 4252672/2^23
Use normal interpretation:
E = 140-(2^(8-1)-1)
(1 + 4252672/2^23)*(2^(140-(2^(8-1)-1)))
2^23 = 8388608;
140-(2^(8-1)-1) = 13;
(1 + 4252672/2^23) = 1.5069580078125
(2^(140-(2^(8-1)-1))) = 8192
(1 + 4252672/2^23)*(2^(140-(2^(8-1)-1))) = 1.5069580078125 * 8192 = 12345
--
Happy day, happy life!