Created
February 11, 2017 13:38
-
-
Save false-git/6f1c3e4b764ce2a0fb74e052f819ab46 to your computer and use it in GitHub Desktop.
偶数パリティの計算
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdint.h> | |
/*! | |
* \brief 7bitの数値を渡すと、偶数パリティを8bit目に入れる | |
* \param[in] val 7bitの数値 | |
* \return 8bit目に偶数パリティを追加したもの | |
*/ | |
uint32_t parity(uint32_t val) { | |
uint32_t orig = (val &= 0x7f); | |
val ^= val << 4; | |
val ^= val << 2; | |
val ^= val << 1; | |
return (val & 0x80) | orig; | |
} | |
int main(int argc, char *argv[]) { | |
for (uint32_t i = 0; i < 128; i++) { | |
printf("%02x:%02x\n", i, parity(i)); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment