常量核心代碼:
`/*
常量:
在程序執(zhí)行過程中,其值不發(fā)生改變的量。
分類:
A:字面值常量
B:自定義常量
字面值常量
A:字符串常量 用雙引號(hào)括起來的內(nèi)容蝴罪。
舉例:"hello","world","HelloWorld"
B:整數(shù)常量 所有的整數(shù)
舉例:100,200
C:小數(shù)常量 所有的小數(shù)
舉例:10.23,110.11
D:字符常量 用單引號(hào)括起來的內(nèi)容
舉例:'a','A','0'
錯(cuò)誤的:'ab'
E:布爾常量 比較特殊
舉例:true,false
F:空常量
舉例:null
*/
class ConstantDemo {
public static void main(String[] args) {
//字符串常量的輸出
System.out.println("hello");
//整數(shù)常量的輸出
System.out.println(100);
//小數(shù)常量的輸出
System.out.println(100.10);
//字符常量的輸出
System.out.println('a');
System.out.println('A');
System.out.println('0');
//這個(gè)是有問題的
//System.out.println('ab');
//布爾常量的輸出
System.out.println(true);
System.out.println(false);
}
}
`
進(jìn)制代碼:
`/*
不同進(jìn)制的數(shù)據(jù)表現(xiàn):
二進(jìn)制:由0,1組成步清。以0b開頭要门。
八進(jìn)制:由0,1,...7組成。以0開頭廓啊。
十進(jìn)制:由0,1,...9組成欢搜。默認(rèn)整數(shù)是十進(jìn)制。
十六進(jìn)制:由0,1,...9,a,b,c,d,e,f(大小寫均可)組成谴轮。以0x開頭炒瘟。
*/
class JinZhiDemo {
public static void main(String[] args) {
System.out.println(100); //十進(jìn)制
System.out.println(0b100); //二進(jìn)制
System.out.println(0100); //八進(jìn)制
System.out.println(0x100); //十六進(jìn)制
}
}`
1:得到下面數(shù)據(jù)的十進(jìn)制值:
0b10101
=1*2^4 + 1*2^2 + 1*2^0
=16 + 4 + 1
=21
0123
=1*8^2 + 2*8^1 + 3*8^0
=64 + 16 + 3
=83
0x3c
=3*16^1 + c*16^0
=48 + 12
=60
2:得到下面數(shù)據(jù)的二進(jìn)制,十進(jìn)制第步,十六進(jìn)制疮装;
52分別得到二進(jìn)制,十進(jìn)制粘都,十六進(jìn)制
得到二進(jìn)制:
52 / 2 = 26 0
26 / 2 = 13 0
13 / 2 = 6 1
6 / 2 = 3 0
3 / 2 = 1 1
1 / 2 = 0 1
0b110100
得到八進(jìn)制:
52 / 8 = 6 4
6 / 8 = 0 6
064
得到十六進(jìn)制:
52 / 16 = 3 4
3 / 16 = 0 3
0x34
3:有符號(hào)數(shù)據(jù)表示法
A:已知某數(shù)X的原碼為10110100B廓推,試求X的補(bǔ)碼和反碼。
符號(hào)位 數(shù)值位
原碼: 1 0110100
反碼: 1 1001011
補(bǔ)碼: 1 1001100
B:已知某數(shù)X的補(bǔ)碼11101110B翩隧,試求其原碼樊展。
符號(hào)位 數(shù)值位
補(bǔ)碼: 1 1101110
反碼: 1 1101101
原碼: 1 0010010
- 郵箱:ithelei@sina.cn
- 技術(shù)討論群:687856230
- GoodLuck