From 3d8b4fd20e0ec21eec88b46b0be5a8280db20870 Mon Sep 17 00:00:00 2001 From: Naveen Ailawadi Date: Fri, 14 Apr 2023 14:09:47 -0400 Subject: [PATCH] Update BytesLib.sol should add support for uint24. I needed this when working on a protocol that packs 4 uint24s and an address for storage optimization (same size as one uint256) --- contracts/BytesLib.sol | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/contracts/BytesLib.sol b/contracts/BytesLib.sol index 532897a..0f2b3a7 100644 --- a/contracts/BytesLib.sol +++ b/contracts/BytesLib.sol @@ -326,6 +326,17 @@ library BytesLib { return tempUint; } + + function toUint24(bytes memory _bytes, uint256 _start) internal pure returns (uint24) { + require(_bytes.length >= _start + 3, "toUint24_outOfBounds"); + uint16 tempUint; + + assembly { + tempUint := mload(add(add(_bytes, 0x3), _start)) + } + + return tempUint; + } function toUint32(bytes memory _bytes, uint256 _start) internal pure returns (uint32) { require(_bytes.length >= _start + 4, "toUint32_outOfBounds");