Decimals and Hex Literals Assignments uintN
In Solidity, we can assign values using decimal and hexadecimal literals to uintN types. These assignments require explicit conversion when assigning to smaller uint types.
Solidity
// Solidity program for Decimals // and Hex Literals Assignments uintN pragma solidity ^0.8.0; contract Conversion { // Decimal literal assignment uint8 public a = 42; // Hexadecimal literal assignment uint256 public b = 0x123456789ABCDEF; } |
Output:
Explicit Conversions in Solidity
Converting data types in Solidity requires explicit conversions. When working with incompatible data formats, this is beneficial. Solidity explicitly converts values via casting operations. To maintain compatibility or execute a particular action, Solidity data types might have distinct sizes and representations.