Created
January 30, 2023 16:02
-
-
Save lcfr-eth/12f18de4543c2a133ac06186f4691676 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.8.0; | |
contract AlignmentChecker { | |
function checkAlignment(uint256 x) public view returns (uint256) { | |
assembly { | |
let alignment := 32 | |
let num := x | |
let mask := and(num, sub(alignment, 1)) | |
let isAligned := iszero(mask) | |
if isAligned { | |
// number is aligned | |
return (0x00, 32) | |
} | |
let remainder := sub(alignment, mask) | |
mstore(0x00, remainder) | |
return (0x00, 32) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment