小编Sat*_*tya的帖子

我想找到bytes32数据的子字符串(索引0到13)并将其转换为uint256数据

我陷入了可靠的代码中。我想要以下数据的子字符串并将其转换为 uint256 数据

bytes32 hmacSha256 = 0xf83bf40815929b2448b230d51fa2eaa5b8ccffd87691db7e62bf817b2cbb56ad;
Run Code Online (Sandbox Code Playgroud)

我想要上述 hmacSha256 数据的前 13 个字符,即“f83bf40815929”及其 uint256 即。4366982094870825。我尝试了很多方法但都失败了。代码和尝试过的代码如下:

// SPDX-License-Identifier: GPL-3.0

pragma solidity >=0.7.0 <0.9.0;

/**
 * @title Storage
 * @dev Store & retrieve value in a variable
 */
contract TestContract {
    
        
    function getsubstring1() public pure returns (string memory, uint256, string memory) {
        bytes32 hmacSha256 = 0xf83bf40815929b2448b230d51fa2eaa5b8ccffd87691db7e62bf817b2cbb56ad;
        bytes memory tempH = bytes(abi.encodePacked(hmacSha256));
        uint256 uintHash = uint256(hmacSha256);
        
        //I want below values as result. 
        // _hs is first 13 chars of hmacSha256.
        //neither i could derive …
Run Code Online (Sandbox Code Playgroud)

solidity

5
推荐指数
1
解决办法
1721
查看次数

标签 统计

solidity ×1