

java binarySearch 구현 부분을 보는데, low와 high 더하고 비트 연산을 통해 처리한 부분이 신기해서 알아보게 되었다. mid 값을 int로 담아도 되는 걸까?
// java의 binarySearch 구현 부분 private static int binarySearch0(long[] a, int fromIndex, int toIndex, long key) { int low = fromIndex; int high = toIndex - 1; while (low <= high) { int mid = (low + high) >>> 1; ... } }왜 아래 코드는 오버플로우 되지 않을까?
int a1 = 1_500_000_000; int b1 = 1_500_000_000; System.out.println((a1 + b1) >>> 1); // 1_500_000_000
// 4비트 시스템에서 예를 들어보자.
0010의 보수는 1110이다.
둘을 더하면, 10000이지만, 초과한 비트에 대해선 버린다. 0이 된다.
1110(-2)에서 양수를 구하려면, 뒤집고 더하면 0010(2)가 된다.
0101_1001_0110_1000_0010_1111_0000_0000 // 1_500_000_000;
+
0101_1001_0110_1000_0010_1111_0000_0000 // 1_500_000_000;
=
1011_0010_1101_0000_0101_1110_0000_0000 // 여기에서 >>> 1 연산
0101_1001_0110_1000_0010_1111_0000_0000 // 즉, 처음과 같아진다.
jq.add(new int[]{i, j});
int[] cur = fq.poll();
int ny = cur[0] + dy[dir];
int nx = cur[1] + dx[dir];
select sum(o1_0.total_all_price),count(o1_0.order_id) from orders o1_0
where o1_0.order_date between '2024-06-10T16:24:20.005+0900' and '2024-06-10T17:24:20.005+0900'
and o1_0.order_status in ('ORDER','DELIVERY','COMPLETE');
Aggregate (group) functions such as COUNT(), MIN(), and SUM() ignore NULL values. COUNT, MIN, SUM은 NULL 값을 무시하고 계산한다고 한다. COUNT()의 경우 NULL이 아닌 값의 개수를 세기 때문에 0이 나오지만, SUM()의 경우 NULL끼리 값을 더해도 NULL이기 때문이다.