Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. function stringToAddress(string memory _a) public pure returns (address) {
  2. bytes memory tmp = bytes(_a);
  3. uint160 iaddr = 0;
  4. uint160 b1;
  5. uint160 b2;
  6. for (uint i = 2; i < 2+2*20; i += 2) {
  7. iaddr *= 256;
  8. b1 = uint160(tmp[i]);
  9. b2 = uint160(tmp[i+1]);
  10. if ((b1 >= 97)&&(b1 <= 102)) b1 -= 87;
  11. else if ((b1 >= 48)&&(b1 <= 57)) b1 -= 48;
  12. if ((b2 >= 97)&&(b2 <= 102)) b2 -= 87;
  13. else if ((b2 >= 48)&&(b2 <= 57)) b2 -= 48;
  14. iaddr += (b1*16+b2);
  15. }
  16. return address(iaddr);
  17. }
  18.  
  19. VehicleRegistry1.sol:266:18: TypeError: Explicit type conversion not allowed
  20. from "bytes1" to "uint160".
  21. b1 = uint160(tmp[i]);
  22. ^-------------^
  23. VehicleRegistry1.sol:267:18: TypeError: Explicit type conversion not allowed from "bytes1" to "uint160".
  24. b2 = uint160(tmp[i+1]);
  25. ^---------------^
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement