I want to exract n bytes from a given bytes data.
//this function extract the first uint8 from a byte data
function extractSelector (bytes data) public constant returns (uint8) {
uint8 sel = uint8(data[0]);
return sel;
}
and the second will extract a web3 signature (65 bytes) from the rest of bytes
function extractSig (bytes data, uint8 from, uint8 n) public constant returns(bytes) {
bytes memory returnValue = new bytes(n);
for (uint8 i = from; i < n; i++) {
returnValue[i] = data[i];
}
return returnValue;
}
I have this data:
data = "0x0436ee02530753fcaecf730e793c2e66791723c6c6a52e385d8200f2dfc1406a6325bba49a98373c9793fa07f82f69c7a1701cbc0cb379b957d5e96d398f1ca1e600"
//extractSelector(data) retruns 4 => it's okay!
but:
extractSig(data,1,65) returns "0x0036ee02530753fcaecf730e793c2e66791723c6c6a52e385d8200f2dfc1406a6325bba49a98373c9793fa07f82f69c7a1701cbc0cb379b957d5e96d398f1ca1e6"
//it seems like the two last "0" jump at the bigining of bytes.
what shall I do to conserve the same data ?