お勉強メモ
シフト演算
最終更新:
匿名ユーザー
-
view
short |
byte |
byte |
|
---|---|---|---|
int型にshortとbyte、byteをつめこみたい
→シフト演算
1)頭がshort型のとき
int ret=0;
short year = (short)5;
byte month = (byte)9;
byte date = (byte)15;
ret = year <<(8*3);//3byte * 8bit
ret += month<<8;//1byte * 8bit
ret +=date;
ret=83888399
→101/00001001/00001111(2進)
(2進)
真ん中がshort
byte |
short |
byte |
|
---|---|---|---|
short month2=(short)9;
byte date2=(byte)15;
int ret2=0;
ret2 =year2<<(8*3);
ret2 +=month2<<(8*1);
ret2 +=date2;
ret=83888399
→101/0000000000001001/00001111(2進)
(2進)