回覆列表
  • 1 # 使用者6847486145697

    用位運算:short int right,left,v=0x2244;right = v & 0x00ff; // 取右8位left = v >> 8; //取左8位printf("right=%#x, left=%#x\n",right,left);==============用聯合體,透過共享記憶體:union { short j; unsigned char a[2]; }x;short int right,left,v=0x2244;x.j = v;right = x.a[0];left = x.a[1];printf("right=%#x, left=%#x\n",right,left);==============輸出都是:right=0x44, left=0x22=================================你的方法也可以:short int j=0x2244;unsigned char right,left;right = (unsigned char) j;left = (unsigned char)(j>>8); // 移位運算部分 加小括號printf("right=%#x, left=%#x\n",right,left);

  • 中秋節和大豐收的關聯?
  • 新買的皮鞋皮表面有味道怎麼辦?