fork download
  1. #include <stdio.h>
  2.  
  3. // MSB is at beginning
  4. void serializeInt(char* buff, int num){
  5. buff[0] = (num >> 24) & 0xFF;
  6. buff[1] = (num >> 16) & 0xFF;
  7. buff[2] = (num >> 8) & 0xFF;
  8. buff[3] = num & 0xFF;
  9. }
  10.  
  11. int deserializeInt(char* buff){
  12. return (buff[0] << 24) + (buff[1] << 16) + (buff[2] << 8) + buff[3];
  13. }
  14. int main(void) {
  15. char buf[4];
  16. int num = 0;
  17. serializeInt(buf, num);
  18. printf("%d\n", deserializeInt(buf));
  19. return 0;
  20. }
  21.  
  22.  
  23.  
Success #stdin #stdout 0s 2168KB
stdin
Standard input is empty
stdout
0