current position:Home>How to convert byte type to integer uint in solidity

How to convert byte type to integer uint in solidity

2022-02-03 20:46:50 Q & A of Denglian community

Solidity in bytes How to convert a type to an integer uint




Take the answer 1:
function bytesToUint(bytes memory b) public view returns (uint256){    uint256 number;    for(uint i= 0; i<b.length; i++){        number = number + uint8(b[i])*(2**(8*(b.length-(i+1))));    }    return (ad, number);}



copyright notice
author[Q & A of Denglian community],Please bring the original link to reprint, thank you.
https://en.netfreeman.com/2022/02/202202032046488062.html

Random recommended