Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [type-casting]

Type casting is the act of converting a value from one data type to another in a computer program.

0
votes
1answer
21 views

Cast contract to address payable

I am wondering if it is possible to cast a contract-reference to an address payable (in order to send to it money) or if it is possible to declare a contract-reference directly payable (with solidity >...
1
vote
1answer
92 views

How to convert bytes32 to uint8 in solidity ^0.5.0?

I can see that conversions from bytes to uint used to be much easier in previous versions of solidity. Now, using the same syntax, I get this error: TypeError: Explicit type conversion not allowed ...
6
votes
2answers
634 views

What's the difference between 'address' and 'address payable'?

I saw a Solidity smart contract where some variables were declared with the type address and some were declared with the type address payable. What are the differences between the two? Do they store ...
1
vote
0answers
39 views

on the implicit type conversion rules in Solidity

Question in one sentence: Are there seperate implicit type conversion rules for function call resolution (other than the conversion rules for the remaining cases)? Regarding the array type ...
0
votes
2answers
194 views

abi.encodePacked with lot of zeros

According this documentation types shorter than 32 bytes are neither zero padded nor sign extended and When I use abi.encodePacked(address, uint, uint, address) I am getting a result with lot of ...
3
votes
1answer
44 views

The most gas-efficient way to convert msg.data to int128?

Is there any more gas-efficient way to convert msg.data to int128? Here is some suggested impl: function bytesToBytes16(bytes b, uint offset) private pure returns (bytes16) { bytes16 out; for (...
1
vote
1answer
24 views

Is there a need to check for null after casting?

Example: MyReceiver my = MyReceiver(_to); // To is an arbitrary address user provided my.someFunction(); // Do I need to check for my == null before calling? Strange enough I do ...
0
votes
1answer
204 views

Going from uint256 to uint8, is it possible?

I have a function that creates random numbers with a maximum value that you gives to it, the function was made to work with any uint256, and using % operator it returns a value between 0 and the ...
0
votes
1answer
262 views

How to typecast keccak256 function with multiple arguments to uint256?

solidity ^0.4.19 (works) uint256 randNonce++; return uint256(keccak256(msg.sender, randNonce, now)) solidity ^0.4.24 (throws) uint256 randNonce++; return uint256(keccak256(abi.encodePacked(msg....
1
vote
1answer
107 views

How to type-cast a function pointer in Solidity?

I have a function that takes a parameter of type function (uint256) view returns (uint256). I want to pass it a pointer to a function of type function (uint256) pure returns (uint256). Obviously ...