In Java, int 有幾多bit...

2007-06-18 8:21 am
如果 int 係 16-bit, 即係最大為65535
但係我試過..

int i=4294967295;
String n = Integer.toBinaryString(i);
System.out.println(n.length());
System.out.println(n);

佢沒有error, 仲出到answer.

有沒有人知道呀????
thanks

回答 (2)

2007-06-18 9:15 am
✔ 最佳答案
Java int data type is a 32-bit signed two's complement integer.
Minimum value = -2,147,483,648
Maximum value = 2,147,483,647

2007-06-18 01:18:42 補充:
int i = 4294967295;以上一句 compiler 會出 error message:「integer number too large: 4294967295」

2007-06-20 00:37:31 補充:
int num = 12345;String numString = Integer.toString( num );String inverseNumString = "";for ( int i = numString.length() - 1 ; i >= 0 ; i-- ){ inverseNumString += numString.charAt( i );}int inverseNum = Integer.parseInt( inverseNumString );
2007-06-18 9:01 am
我諗應該係32bit. 好簡單,你用sizeof(int) 看看就知了


收錄日期: 2021-04-13 15:57:19
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20070618000051KK00087

檢視 Wayback Machine 備份