진수에 대해서
class A {
}
public class Day3 {
public static void main(String[] args) {
A a = new A();
System.out.println(a); // a의 16진수 주소값
System.out.println(a.hashCode()); // 10진수 주소값
int n1 = 1234;
System.out.println(Integer.toBinaryString(n1)); // 10진수를 2진수로
int n2 = 0x1234;
System.out.println(Integer.toBinaryString(n2)); // 16진수를 2진수로
}
}
public class Day3 {
static void func01(int n) {
String s1 = Integer.toBinaryString(n);
System.out.println(s1);
char[] ar = new char[32 - s1.length()]; // 16진수를 2진수로 표현하기 위해선 최대 32bit필요
for (int i = 0; i < ar.length; i++)
ar[i] = '0';
String s2 = new String(ar);
StringBuffer s3 = new StringBuffer(s2 + s1); // CRUD(자료구조)가능한 String객체
System.out.println(s3); // 2진수를 32자리 수로 표현
// 16진수의 한자리는 4bit로 표현(2진수의 4자리수) > 4자리씩 끊기
for (int i = 0; i < 7; i++) {
s3.insert((7 - i) * 4, ' ');
}
System.out.println(s3);
}
public static void main(String[] args) {
func01(0x1234);
int a = 0x1234;
int b = 0xabcd;
int c = a & b; // 비트연산자& (and)
int d = a | b; // 비트연산자 | (or)
func01(c);
func01(d);
}
}