For example,
I need to slice my bytes32 variable to chunks, and put result into 5 variables, saving the order, bytes2
, bytes2
, bytes2
, bytes2
, bytes8
, bytes1
(aka byte
), the order should be saved and I don't really care about the rest of bytes.
Is solidity has some tools for that? Or it is only possible with bit operations.
I found some difficulties working with this low-level types.
UPDATE:
So I did prepare this function which parses numBytes
bytes from source
starting from start
byte.
function bytesChunck(bytes32 source, uint start, uint numBytes) constant returns(uint _result){
uint counter = 0;
uint result;
for(uint i = 0; i < numBytes; i++) {
result += uint8(source[start + i]);
}
return result;
//
}
then I just convert result to needed bytes, like bytes8(result)
. But it seems to be overflowed, since if I have like 8 bytes it first bytes always zeros. Any ideas? :)
Thank you.