Timeline for How to convert an bytes to address in Solidity?
Current License: CC BY-SA 3.0
8 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
May 10, 2022 at 11:18 | comment | added | ASHKARAN | for me uint c = uint(b[i]); should be uint c = uint(uint8(b[i])); | |
Nov 6, 2017 at 9:13 | comment | added | erkt | It also helps to think what happens in the case of base 10 strings. Because what were essentially doing in this function is taking the string representation of a number and converting it to a number type. Hope that helps @MiguelMota | |
Nov 6, 2017 at 9:12 | comment | added | erkt | We repeat with the next character in the byte ("A"). We cast that to a uint which gives us "A" == 65. We fall into the 2nd "if". We then take result which equals 1 multiply it by 16 and add 65-55 = 10, which is what A is in hex. | |
Nov 6, 2017 at 9:12 | comment | added | erkt | For sure! Assume our address is: 0x1A3b4 which you will give to the function as "1A3b4". What happens is: 1) We enter in the for loop 2) Grab the first character ("1") and cast it to a uint. In this case the ASCII corresponding to "1" is 49. 3) Since "1" = 49, we fall into the 1st "if" clause. It subtracts 48 to get integer 1. Then we take result, multiply it by 16 because address is base 16, and add it to the result. | |
Oct 26, 2017 at 1:03 | comment | added | Miguel | Can you explain how this works? | |
Jun 28, 2017 at 13:18 | vote | accept | 徐欢欢 | ||
Jun 24, 2017 at 5:27 | review | Late answers | |||
Jun 24, 2017 at 5:28 | |||||
Jun 24, 2017 at 5:08 | history | answered | erkt | CC BY-SA 3.0 |