Explicit conversion

Explicit conversion is required when a compiler does not perform implicit conversion either because of loss of data or a value containing data not falling within a target data type range. Solidity provides a function for each value type for explicit conversion. Examples of explicit conversion are uint16 conversion to uint8. Data loss is possible in such cases.

The following code listing shows examples for both implicit and explicit conversions:

  • ConvertionExplicitUINT8toUINT256: This function executed explicit conversion from uint8 to uint256. It is to be noted that this conversion was also possible implicitly.
  • ConvertionExplicitUINT256toUINT8: This function executed explicit conversion from uint256 to uint8. This conversion ...

Get Solidity Programming Essentials now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.