「シフト演算」(2005/09/15 (木) 13:51:22) の最新版変更点
追加された行は緑色になります。
削除された行は赤色になります。
<br>
<table style="width: 244px; height: 56px;" border="1">
<tbody>
<tr>
<th>short<br></th>
<th><br></th>
<th>byte<br></th>
<th>byte<br></th>
</tr>
<tr>
<td style="background-color: rgb(102, 204, 204);"><br></td>
<td style="background-color: rgb(102, 204, 204);"><br></td>
<td style="background-color: rgb(102, 255, 255);"><br></td>
<td style="background-color: rgb(102, 255, 255);"><br></td>
</tr>
</tbody>
</table>
<br>
int型にshortとbyte、byteをつめこみたい<br>
→シフト演算<br>
1)頭がshort型のとき<br>
<hr size="2" width="100%">
int ret=0;<br>
short year = (short)5;<br>
byte month = (byte)9;<br>
byte date = (byte)15;<br>
<br>
ret = year <<(8*3);//3byte * 8bit<br>
ret += month<<8;//1byte * 8bit<br>
ret +=date;<br>
<br>
ret=<br>
→(10進)<br>
→(2進)<br>
<br>
(2進)<br>
<hr size="2" width="100%">
真ん中がshort<br>
<table style="width: 186px; height: 56px;" border="1">
<tbody>
<tr>
<th>byte<br></th>
<th>short<br></th>
<th><br></th>
<th>byte<br></th>
</tr>
<tr>
<td style="background-color: rgb(51, 255, 255);"><br></td>
<td style="background-color: rgb(102, 204, 204);"><br></td>
<td style="background-color: rgb(102, 204, 204);"><br></td>
<td style="background-color: rgb(51, 255, 255);"><br></td>
</tr>
</tbody>
</table>
byte year2=(byte)5;<br>
short month2=(short)9;<br>
byte date2=(byte)15;<br>
<br>
int ret2=0;<br>
ret2 =year2<<(8*3);<br>
ret2 +=month2<<<span style="color: rgb(51, 102, 255);"><b>(8*1)</b>;<br>
<span style="color: rgb(0, 0, 0);">ret2 +=date2;</span><br>
<br></span>ret=<br>
→(10進)<br>
→(2進)<br>
<br>
(2進)<br>
<hr size="2" width="100%">
<br>
<br>
<br>
<br>
<table style="width: 244px; height: 56px;" border="1">
<tbody>
<tr>
<th>short<br></th>
<th><br></th>
<th>byte<br></th>
<th>byte<br></th>
</tr>
<tr>
<td style="background-color: rgb(102, 204, 204);"><br></td>
<td style="background-color: rgb(102, 204, 204);"><br></td>
<td style="background-color: rgb(102, 255, 255);"><br></td>
<td style="background-color: rgb(102, 255, 255);"><br></td>
</tr>
</tbody>
</table>
<br>
int型にshortとbyte、byteをつめこみたい<br>
→シフト演算<br>
1)頭がshort型のとき<br>
<hr size="2" width="100%">
int ret=0;<br>
short year = (short)5;<br>
byte month = (byte)9;<br>
byte date = (byte)15;<br>
<br>
ret = year <<(8*3);//3byte * 8bit<br>
ret += month<<8;//1byte * 8bit<br>
ret +=date;<br>
<br>
ret=83888399<br>
→101/00001001/00001111(2進)<br>
<br>
(2進)<br>
<hr size="2" width="100%">
真ん中がshort<br>
<table style="width: 186px; height: 56px;" border="1">
<tbody>
<tr>
<th>byte<br></th>
<th>short<br></th>
<th><br></th>
<th>byte<br></th>
</tr>
<tr>
<td style="background-color: rgb(51, 255, 255);"><br></td>
<td style="background-color: rgb(102, 204, 204);"><br></td>
<td style="background-color: rgb(102, 204, 204);"><br></td>
<td style="background-color: rgb(51, 255, 255);"><br></td>
</tr>
</tbody>
</table>
byte year2=(byte)5;<br>
short month2=(short)9;<br>
byte date2=(byte)15;<br>
<br>
int ret2=0;<br>
ret2 =year2<<(8*3);<br>
ret2 +=month2<<<span style="color: rgb(51, 102, 255);"><b>(8*1)</b>;<br>
<span style="color: rgb(0, 0, 0);">ret2 +=date2;</span><br>
<br></span>ret=83888399<br>
→101/0000000000001001/00001111(2進)<br>
<br>
(2進)<br>
<hr size="2" width="100%">
<br>
<br>
<br>
表示オプション
横に並べて表示:
変化行の前後のみ表示: