精華區beta C_and_CPP 關於我們 聯絡資訊
網址: https://stackoverflow.com/questions/13926760/the-reason-behind-endianness 網址裡面有提到big跟little的優缺點,但小弟資質不良,無法完全理解,想請各位前輩開 釋 little-endian: 1. The little-endian system has the property that the same value can be read from memory at different lengths without using different addresses 請問,at different lengths without using different addresses是什麼意思? 2. When adding or subtracting multi-byte numbers, the least significant byte must be fetched first to see if there is a carryover to more significant bytes. Because the least-significant byte is read first in little-endian numbers, the system can parallelize and begin calculation on this byte while fetching the following byte(s). 這一段我看得懂,大致上的意思是little-endian有辦法一邊fetch lower byte 一邊做計 算,如果是big-endian就必須全部fetch下來才可以做計算 big-endian: 1. it is simple to tell whether a number is positive or negative by simply examining the bit at offset 0 in the lowest order byte. 這邊我也看得懂,big-endian的優點就是很容易比出兩個數字的大小。 2. binary digits are ordered as most people order base-10 digits. This is advantageous performance-wise when converting from binary to decimal. 不懂,為什麼從2進制轉換成10進制會有performance-wise? 我認為不管是big還是little,轉成10進制的效能都是一樣的,只是big從MSB開始加, little從LSB開始加 請各位指點迷津,謝謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 36.231.76.103 ※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1524056539.A.B74.html
chuegou: 應該就是字面上的意思 一個是指標指到頭 一個指到尾 04/18 21:12
bibo9901: 1.的意思是同一個地址可以當int*和short* 04/18 22:42
bibo9901: 因為開頭對齊, 所以轉型很容易, 只有寬度不同而已 04/18 22:43
bibo9901: 而且little轉10進位並不是從LSB開始一路往回就好 04/18 22:44
Lipraxde: 從高的開始轉,那萬一比它的有進位是不是就要回頭算? 04/19 00:33
Lipraxde: *比它低的 04/19 00:33
> -------------------------------------------------------------------------- < 作者: enonrick (EnonRick) 看板: C_and_CPP 標題: Re: [問題] big-endian vs little-endian 時間: Thu Apr 19 14:26:58 2018 ※ 引述《zzss2003 (brotherD)》之銘言: : 網址: https://stackoverflow.com/questions/13926760/the-reason-behind-endianness : 網址裡面有提到big跟little的優缺點,但小弟資質不良,無法完全理解,想請各位前輩開 : 釋 : little-endian: : 1. The little-endian system has the property that the same value can be read : from memory at different lengths without using different addresses value 4A in little-endian char [4A] short [4A 00] int [4A 00 00 00] long [4A 00 00 00 00 00 00 00] 可以節省記憶體 https://en.wikipedia.org/wiki/Endianness#Optimization : 請問,at different lengths without using different addresses是什麼意思? : 2. When adding or subtracting multi-byte numbers, the least significant byte : must be fetched first to see if there is a carryover to more significant : bytes. Because the least-significant byte is read first in little-endian : numbers, the system can parallelize and begin calculation on this byte while : fetching the following byte(s). msb lsb [010010101 10111010] +[010001100 11100010] --------------------- 不用考慮進位借位問題讀完第一個 lsb byte 就可以算 : 這一段我看得懂,大致上的意思是little-endian有辦法一邊fetch lower byte 一邊做計 : 算,如果是big-endian就必須全部fetch下來才可以做計算 : big-endian: : 1. it is simple to tell whether a number is positive or negative by simply : examining the bit at offset 0 in the lowest order byte. 跟比大小無關 -1022 little-endian [00000010 11111100] big-endian [11111100 00000010] big endian 讀第1個bit就可以知道是正是負 : 這邊我也看得懂,big-endian的優點就是很容易比出兩個數字的大小。 : 2. binary digits are ordered as most people order base-10 digits. This is : advantageous performance-wise when converting from binary to decimal. : 不懂,為什麼從2進制轉換成10進制會有performance-wise? : 我認為不管是big還是little,轉成10進制的效能都是一樣的,只是big從MSB開始加, : little從LSB開始加 : 請各位指點迷津,謝謝 假設 int a = e; &a = 0xa 0xa [000000000] 0xb [100101001] 0xc [100010011] 0xd [111101011] 不論little big 要讀 a 的值都會至 address 0xa 讀值 big直出 a->b->c->d 讀下去 little 就要先 offset後 再d->c->b->a 直覺上效能會比 big 慢,但這個差異可忽略