お勉強メモ

シフト演算

最終更新:

匿名ユーザー

- 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




byte year2=(byte)5;
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進)




記事メニュー
人気記事ランキング
目安箱バナー