1.´óС¶ËµÄÆðÔ´£º
¹ØÓÚ´ó¶ËС¶ËÃû´ÊµÄÓÉÀ´£¬ÓÐÒ»¸öÓÐȤµÄ¹ÊÊ£¬À´×ÔÓÚJonathan SwiftµÄ¡¶¸ñÀû·ðÓμǡ·£ºLilliputºÍBlefuscuÕâÁ½¸öÇ¿¹úÔÚ¹ýÈ¥µÄ36¸öÔÂÖÐÒ»Ö±ÔÚ¿àÕ½¡£Õ½ÕùµÄÔÒò£º´ó¼Ò¶¼ÖªµÀ£¬³Ô¼¦µ°µÄʱºò£¬ÔʼµÄ·½·¨ÊÇ´òÆƼ¦µ°½Ï´óµÄÒ»¶Ë£¬¿ÉÒÔÄÇʱµÄ»ÊµÛµÄ×游ÓÉÓÚСʱºî³Ô¼¦µ°£¬°´ÕâÖÖ·½·¨°ÑÊÖָŪÆÆÁË£¬Òò´ËËûµÄ¸¸Ç×£¬¾ÍÏÂÁÃüÁîËùÓеÄ×ÓÃñ³Ô¼¦µ°µÄʱºò£¬±ØÐëÏÈ´òÆƼ¦µ°½ÏСµÄÒ»¶Ë£¬Î¥ÁîÕßÖØ·£¡£È»ºóÀÏ°ÙÐÕ¶Ô´Ë·¨ÁΪ·´¸Ð£¬Æڼ䷢ÉúÁ˶à´ÎÅÑÂÒ£¬ÆäÖÐÒ»¸ö»ÊµÛÒò´ËËÍÃü£¬ÁíÒ»¸ö¶ªÁËÍõ룬²úÉúÅÑÂÒµÄÔÒò¾ÍÊÇÁíÒ»¸ö¹ú¼ÒBlefuscuµÄ¹úÍõ´ó³¼É¿¶¯ÆðÀ´µÄ£¬ÅÑÂÒƽϢºó£¬¾ÍÌÓµ½Õâ¸öµÛ¹ú±ÜÄÑ¡£¾Ý¹À¼Æ£¬ÏȺ󼸴ÎÓÐ11000ÓàÈËÇéÔ¸ËÀÒ²²»¿ÏÈ¥´òÆƼ¦µ°½ÏСµÄ¶Ë³Ô¼¦µ°¡£Õâ¸öÆäʵ·í´Ìµ±Ê±Ó¢¹úºÍ·¨¹úÖ®¼ä³ÖÐøµÄ³åÍ»¡£Danny CohenһλÍøÂçÐÒéµÄ¿ª´´Õߣ¬µÚÒ»´ÎʹÓÃÕâÁ½¸öÊõÓïÖ¸´ú×Ö½Ú˳Ðò£¬ºóÀ´¾Í±»´ó¼Ò¹ã·º½ÓÊÜ¡£
Big-EndianºÍLittle-EndianµÄ¶¨ÒåÈçÏ£º
1) Little-Endian¾ÍÊǵÍλ×Ö½ÚÅÅ·ÅÔÚÄÚ´æµÄµÍµØÖ·¶Ë£¬¸ßλ×Ö½ÚÅÅ·ÅÔÚÄÚ´æµÄ¸ßµØÖ·¶Ë¡£
2) Big-Endian¾ÍÊǸßλ×Ö½ÚÅÅ·ÅÔÚÄÚ´æµÄµÍµØÖ·¶Ë£¬µÍλ×Ö½ÚÅÅ·ÅÔÚÄÚ´æµÄ¸ßµØÖ·¶Ë¡£
2.¾ÙÒ»¸öÀý×Ó£¬±ÈÈçÊý×Ö0x12 34 56 78ÔÚÄÚ´æÖеıíʾÐÎʽΪ£º
1)´ó¶Ëģʽ£º
µÍµØÖ· -----------------> ¸ßµØÖ·
0x12 | 0x34 | 0x56 | 0x78
2)С¶Ëģʽ£º
µÍµØÖ· ------------------> ¸ßµØÖ·
0x78 | 0x56 | 0x34 | 0x12
¿É¼û£¬´ó¶ËģʽºÍ×Ö·û´®µÄ´æ´¢Ä£Ê½ÀàËÆ¡£
3.Ϊʲô»áÓдóС¶Ëģʽ֮·ÖÄØ£¿
ÕâÊÇÒòΪÔÚ¼ÆËã»úϵͳÖУ¬ÎÒÃÇÊÇÒÔ×Ö½ÚΪµ¥Î»µÄ£¬Ã¿¸öµØÖ·µ¥Ôª¶¼¶ÔÓ¦×ÅÒ»¸ö×Ö½Ú£¬Ò»¸ö×Ö½ÚΪ8bit¡£µ«ÊÇÔÚCÓïÑÔÖгýÁË8bitµÄcharÖ®Í⣬»¹ÓÐ16bitµÄshortÐÍ£¬32bitµÄlongÐÍ£¨Òª¿´¾ßÌåµÄ±àÒëÆ÷£©£¬ÁíÍ⣬¶ÔÓÚλÊý´óÓÚ8λµÄ´¦ÀíÆ÷£¬ÀýÈç16λ»òÕß32λµÄ´¦ÀíÆ÷£¬ÓÉÓڼĴæÆ÷¿í¶È´óÓÚÒ»¸ö×Ö½Ú£¬ÄÇô±ØÈ»´æÔÚ×ÅÒ»¸öÈç¹û½«¶à¸ö×Ö½Ú°²ÅŵÄÎÊÌâ¡£Òò´Ë¾Íµ¼ÖÂÁË´ó¶Ë´æ´¢Ä£Ê½ºÍС¶Ë´æ´¢Ä£Ê½¡£ÀýÈçÒ»¸ö16bitµÄshortÐÍx£¬ÔÚÄÚ´æÖеĵØַΪ0x0010£¬xµÄֵΪ0x1122£¬ÄÇô0x11Ϊ¸ß×Ö½Ú£¬0x22ΪµÍ×Ö½Ú¡£¶ÔÓÚ´ó¶Ëģʽ£¬¾Í½«0x11·ÅÔڵ͵ØÖ·ÖУ¬¼´0x0010ÖУ¬0x22·ÅÔڸߵØÖ·ÖУ¬¼´0x0011ÖС£Ð¡¶Ëģʽ£¬¸ÕºÃÏà·´¡£ÎÒÃdz£ÓõÄX86½á¹¹ÊÇС¶Ëģʽ£¬¶øKEIL C51ÔòΪ´ó¶Ëģʽ¡£ºÜ¶àµÄARM£¬DSP¶¼ÎªÐ¡¶Ëģʽ¡£ÓÐЩARM´¦ÀíÆ÷»¹¿ÉÒÔÓÉÓ²¼þÀ´Ñ¡ÔñÊÇ´ó¶Ëģʽ»¹ÊÇС¶Ëģʽ¡£
Ò»°ã²Ù×÷ϵͳ¶¼ÊÇС¶Ë£¬¶øͨѶÐÒéÊÇ´ó¶ËµÄ.
#include<stdio.h> union var{ char c[4]; int i; };
int main(){ union var data; data.c[0] = 0x04;//ÒòΪÊÇcharÀàÐÍ£¬Êý×Ö²»ÒªÌ«´ó£¬ËãËãasciiµÄ·¶Î§~ data.c[1] = 0x03;//д³É16½øÖÆΪÁË·½±ãÖ±½Ó´òÓ¡ÄÚ´æÖеÄÖµ¶Ô±È data.c[2] = 0x02; data.c[3] = 0x11; //Êý×éÖÐϱêµÍµÄ£¬µØÖ·Ò²µÍ£¬°´µØÖ·´ÓµÍµ½¸ß£¬ÄÚ´æÄÚÈÝÒÀ´ÎΪ£º04,03,02,11¡£×ܹ²ËÄ×Ö½Ú£¡ //¶ø°ÑËĸö×Ö½Ú×÷Ϊһ¸öÕûÌ壨²»·ÖÀàÐÍ£¬Ö±½Ó´òÓ¡Ê®Áù½øÖÆ£©£¬Ó¦¸Ã´ÓÄÚ´æ¸ßµØÖ·µ½µÍµØÖ·¿´£¬0x11020304£¬µÍλ04·ÅÔڵ͵ØÖ·ÉÏ¡£ printf("%x\n",data.i); } |