[WTF] 轉十六進位

不管用什麼語言寫數值輸出成十六進位顯示

寫成十六個值一一 if else 或 switch 判斷的,請給自己一巴掌….

Update: 補上兩個例子(手上剛好有很多….)

switch (value)
{
case 0:
return '0';
case 1:
return '1';
case 2:
return '2';
case 3:
return '3';
case 4:
return '4';
case 5:
return '5';
case 6:
return '6';
case 7:
return '7';
case 8:
return '8';
case 9:
return '9';
case 10:
return 'A';
case 11:
return 'B';
case 12:
return 'C';
case 13:
return 'D';
case 14:
return 'E';
case 15:
return 'F';
}
if (value == 15)
temp[i++] = 'F';
if (value == 14)
temp[i++] = 'E';
if (value == 13)
temp[i++] = 'D';
if (value == 12)
temp[i++] = 'C';
if (value == 11)
temp[i++] = 'B';
if (value == 10)
temp[i++] = 'A';
if (value == 9)
temp[i++] = '9';
if (value == 8)
temp[i++] = '8';
if (value == 7)
temp[i++] = '7';
if (value == 6)
temp[i++] = '6';
if (value == 5)
temp[i++] = '5';
if (value == 4)
temp[i++] = '4';
if (value == 3)
temp[i++] = '3';
if (value == 2)
temp[i++] = '2';
if (value == 1)
temp[i++] = '1';
if (value == 0)
temp[i++] = '0';

  • 留言者: swanky
  • Email: swanky.hsiao@gmail.com
  • 網址: http://ciyawasay.blogspot.com/
  • 日期: 2005-11-28 23:57:22

不太懂耶~

可以示範一下你說的這種寫法嗎? 🙂


  • 留言者: Duncan
  • Email:
  • 網址:
  • 日期: 2005-12-02 19:41:53

一切都是幻覺,你騙不了我的!!

我的話大概先寫好陣列,直接取把值當作 index 就很勤勞了。


  • 留言者: JiaYun
  • Email:
  • 網址:
  • 日期: 2005-12-07 14:58:40

其實還有更勤勞的版本,怕貼出來嚇到人….

我還真是被嚇到了

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *