1
此代碼將unsigned long
向量變量cR1
轉換爲NB_ERRORS
數字(在a
變量中我輸出這些數字)。將二進制無符號向量轉換爲十進制列表
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int EXT_DEGREE = 8;
int NB_ERRORS = 8;
int BIT_SIZE_OF_LONG = 32;
typedef unsigned short gf_t;
int main(void){
int j, k, l;
gf_t a;
unsigned long cR1 [] = {418636844,2037720909}; //example
for (l = 0; l < NB_ERRORS; ++l) {
k = (l * EXT_DEGREE)/BIT_SIZE_OF_LONG;
j = (l * EXT_DEGREE) % BIT_SIZE_OF_LONG;
a = cR1[k] >> j;
if(j + EXT_DEGREE > BIT_SIZE_OF_LONG)
a ^= cR1[k + 1] << (BIT_SIZE_OF_LONG - j);
a &= ((1 << EXT_DEGREE) - 1);
printf("a = %d\n", a);
}
比如我有一個CR1陣列後面兩個要素:
0,0,1,1,0,1,0,0,0,0,1,0,0,1,1,1,1,1,0,0,1,1,1,1,0,0,0,1,1,0,0,0
1,0,1,1,0,0,1,0,1,1,1,0,0,1,0,0,1,0,1,0,1,1,1,0,1,0,0,1,1,1,1,0
執行該代碼我得到:
a = 44
a = 228
a = 243
a = 24
a = 77
a = 39
a = 117
a = 121
此代碼從右轉換左,我想修改從左到右轉換。我可以在哪裏修改這個?
請提供顯示你的問題很短的編譯例子 - 如果人們可以只剪切和粘貼代碼,並嘗試自己,他們更容易幫助你 –
'此代碼由右至左轉換,我想修改從右向左轉換的好消息!你不需要改變任何東西! – Eregrith
@AdrianCornish很難提供一個簡短的例子,這個例子是最短的。 – Juan