Most Significant Bit
Most Significant Bit // SPDX-License-Identifier: MIT pragma solidity ^0.8.19; contract MostSignificantBit { /// 이분 탐색을 사용해 x의 최상위 비트를 찾는다 function findMostSignificantBitBinarySearch(uint256 x) public pure returns(uint8 r) { if (x >= 2 ** 128) { x >>= 128; r += 128; } if (x >= 2 ** 64) { x >>= 64; r += 64; } if (x >= 2 ** 32) { x >>= 32; r += 32; } if (x >= 2 ** 16) { x >>= 16; r += 16; } if (x >..
Solidity
2023. 3. 21. 19:09