[Ethereum] How to modify bytes32 result to uint

bytes32

I want to separate three last digits of the most recent block header hash and get the result as uint.

I can get the answer as bytes32 by this code, but how can I change this result to uint?

contract test
{
    bytes32 lastblockhashused;
    uint lastblocknumberused;

    function test()
    {
        lastblocknumberused = (block.number-1)  ;               
        lastblockhashused = block.blockhash(lastblocknumberused);
    }

    function getTest1() constant returns (bytes32) {
        bytes32 number1 =lastblockhashused;
        return number1 & 0xfff;
    }
}

Best Answer

Or just do away with your number1 variable completely, while also remembering to change the return type:

function getTest1() constant returns (uint) {
        return uint(lastblockhashused) & 0xfff;
    }
Related Topic