Java programming

[Java programming] μžλ°” ν”„λ‘œκ·Έλž˜λ° : 2μ§„μˆ˜ , 8μ§„μˆ˜, 16μ§„μˆ˜ ν‘œν˜„ν•˜κΈ°

ν”„λ‘œκ·Έλž˜λ¨Έ μ˜€μ›” 2023. 7. 21.

β–¦ 2μ§„μˆ˜

 

2μ§„μˆ˜λ₯Ό ν‘œν˜„ν•΄μ•Όν•  땐 숫자 μ•žμ— 0Bλ₯Ό μ¨μ•Όν•œλ‹€.(bλŠ” μ†Œλ¬Έμžλ‘œλ„ 써도 λœλ‹€.)

 

μ˜ˆμ‹œ)

1
2
3
4
5
6
7
public class BinaryTest {
    public static void main(String[] args) {
        int bNum = 0B1010;
        System.out.println(bNum);
    }
}
 
cs

 

bNUM은 좜λ ₯해보면 1010(2)은 10μ§„μˆ˜λ‘œ 10μ΄λ―€λ‘œ 좜λ ₯ 값은 10이 λ‚˜μ˜¨λ‹€.

 

 

 

 

β–¦ 8μ§„μˆ˜

 

8μ§„μˆ˜λ₯Ό ν‘œν˜„ν•΄μ•Όν•  땐 숫자 μ•žμ— 0λ₯Ό μ¨μ•Όν•œλ‹€.

 

μ˜ˆμ‹œ)

1
2
3
4
5
6
7
public class BinaryTest{
    public static void main(String[] args) {
        int oNum = 012;
        System.out.println(oNum);
    }
}
 
cs

 

oNUM은 좜λ ₯해보면 12(8)은 10μ§„μˆ˜λ‘œ 10μ΄λ―€λ‘œ 좜λ ₯ 값은 10이 λ‚˜μ˜¨λ‹€.

 

 

 

β–¦ 16μ§„μˆ˜

 

16μ§„μˆ˜λ₯Ό ν‘œν˜„ν•΄μ•Όν•  땐 숫자 μ•žμ— 0Xλ₯Ό μ¨μ•Όν•œλ‹€.(xλŠ” μ†Œλ¬Έμžλ‘œλ„ 써도 λœλ‹€.)

 

μ˜ˆμ‹œ)

1
2
3
4
5
6
7
public class BinaryTest{
    public static void main(String[] args) {
        int xNum = 0XA;
        System.out.println(xNum);
    }
}
 
cs

xNUM은 좜λ ₯해보면 A(16)은 10μ§„μˆ˜λ‘œ 10μ΄λ―€λ‘œ 좜λ ₯ 값은 10이 λ‚˜μ˜¨λ‹€.

 

 

λŒ“κΈ€