パリティチェック実装 VB => Java(Android) 移植 2022_02_10 メモ

置き換え

-----------------
[VB] -128
&H80 

[java]
Byte.MIN_VALUE  

----------------
[VB] 128
&H7F

[java]
Byte.MAX_VALUE

-----

[コード: パリティビット を付加する]

/**
* SetParity
* バイト列の最上位ビットにパリティ情報を付加する
*
* pData Byte() I バイト列
* intLen Integer I 対象の長さ
* pType Integer I パリティ種類(0:Even 1:Od
*
* 戻り値 なし
*/
private static void SetParity(byte[] pData, int intLen,int pType) {

int I;
int J;
int C;
for (I = 0; I < intLen - 1; I++) {
if (I >= pData.length) {
break;
}
pData[I] = (byte) (pData[I] & Byte.MAX_VALUE);
J = 1;
C = (pType & 1);
while( J >= Byte.MIN_VALUE) {
if((pData[I] & J) != 0) {
// ^ => VB XOR
C = C ^ 1;
}
J *= 2;
}
if (C == 1) {
// | , ビットOR
pData[I] = (byte) (pData[I] | Byte.MIN_VALUE);
}
}

}

 

[コード: パリティチェック]

private static boolean RemoveParity(byte[] pData, int intLen, int pType) {

int I;
int J;
int C;

boolean removeParity = false;
// 'パリティチェック
for(I = 0; I < pData.length - 1; I++) {
if (I >= pData.length) {
break;
}
J = 1;
// & , XOR
C = (pType & 1);
while (J >= Byte.MAX_VALUE + 1) {
if ((pData[I] & J) != 0) {
C = C ^ 1;
}
J *= 2;
if (C == 1) {
break;
}
}
} //=== END for
for(I = 0; I < intLen - 1; I++) {
if(I >= pData.length) {
break;
}
pData[I] = (byte)(pData[I] & Byte.MIN_VALUE);
}
removeParity = true;
return removeParity;
}