In one uint256 I want to store the entire sender's address of 20 bytes and then 12 bytes of a second address. In this case the example addresses will be the following:
0x9E1C3a90c6EB03F914dF819CA9b3c891DE003301 sender address
0xdFd6b3Fd6E13C3E6AE53d510bFAb5217b5b39FeC secondary / other address
I send a tx with the setCharacter function below.
setCharacter(0xdFd6b3Fd6E13C3E6AE53d510bFAb5217b5b39FeC, 25)
Now when I use the getter to retrieve the data I get the following.
getCharacter(25)
owner_address -> 0x9E1C3a90c6EB03F914dF819CA9b3c891DE003301
secondpart -> 0
The secondpart = 0 is not what I am shooting for. I want secondpart to be equal to the equiv of 0xAE53d510bFAb5217b5b39FeC (last 12 bytes of 2nd address) or 0xdFd6b3Fd6E13C3E6AE53d510 (first 12 bytes of the 2nd address). Any pointers on where I went wrong? Thank you for any help.
contract storagetest8 {
mapping(uint256 => uint256) inventories;
function setCharacter(address other_address, uint256 index1)
external
{
uint256 _id = uint256(msg.sender);
_id |= uint96(other_address)<<160;
inventories[index1] = _id;
}
function getCharacter(uint256 index1)
external view
returns(address owner_address, uint256 secondpart) {
uint256 _id = inventories[index1];
owner_address = address(_id);
secondpart = uint256(uint96(_id>>160));
}
}