fork download
  1. #define MAX_NUM 3 // 変数の数
  2. #define MAX_BIT_KETA 2 // 有効なビットの桁数
  3.  
  4. #include <stdio.h>
  5.  
  6. int main()
  7. {
  8. unsigned char fromData[MAX_NUM] = {0x03, 0x01, 0x02};
  9. unsigned short toData = 0;
  10. int i, j;
  11.  
  12. for (i = 0; i < MAX_BIT_KETA; i++) {
  13. for (j = 0; j < MAX_NUM; j++) {
  14. toData <<= 1;
  15. if (fromData[j] & 0x01) {
  16. toData |= 0x01;
  17. }
  18. fromData[j] >>= 1;
  19. }
  20. }
  21.  
  22. printf("%x", toData);
  23. }
Runtime error #stdin #stdout 0.01s 1676KB
stdin
Standard input is empty
stdout
35