Solidity-004 ByteContract

pragma solidity ^0.8.9; 

// Solidity contract to demonstrate basic operations with byte types
contract BytesContractbytesContract { 

     // State variable 'aa' of type bytes1 initialized with hexadecimal value 0x65
     bytes1 aa = 0x65; 

     // State variable 'bb' of type bytes1, initialized by casting the integer 10 to bytes1
     bytes1 bb = bytes1(uint8(10)); 

     // State variable 'cc' of type bytes2, initialized by casting the integer 256 to bytes2
     bytes2 cc = bytes2(uint16(256)); 

     // State variable 'dd' of type bytes1, initialized with the ASCII value of 'a'
     bytes1 dd = 'a'; 

     // State variable 'ff' of type bytes1, not initialized and defaults to 0x00
     bytes1 ff ; 

    // Function to get the value of 'ff'; returns 0x00 as 'ff' is uninitialized
    function getintff() public returns (bytes1) { 
      return ff; // returns 0x00 
    } 

    // Function to return the uint equivalent of 'aa'
    function getintaa()  public returns (uint) { 
      return uint8(aa); // returns 101 
    } 

    // Function to get the byte value of 'aa'
    function getbyteaa() public  returns (bytes1) { 
      return aa; // returns 0x65 
    } 

    // Function to get the byte value of 'bb'
    function getbytebb() public  returns (bytes1) { 
      return bb; // returns 0x0a 
    } 

    // Function to return the uint equivalent of 'bb'
    function getintbb() public  returns (uint) { 
      return uint8(bb); // returns 10 
    } 

    // Function to get the 2-byte value of 'cc'
    function getbytecc() public  returns (bytes2) { 
      return cc; // returns 0x0100 
    } 

    // Function to return the uint equivalent of 'cc'
    function getintcc() public  returns (uint) { 
      return uint16(cc); // returns 256 
    } 

    // Function to get the byte value of 'dd'
    function getbytedd() public  returns (bytes2) { 
      return dd; // returns 0x6100 or 0x61 for bytes1 
    } 

    // Function to return the uint equivalent of 'dd'
    function getintdd()  public returns (uint) { 
      return uint8(dd); // returns 97 
    } 

}    

//Deploy screenshot show:

Solidity-004 ByteContract_第1张图片

你可能感兴趣的:(Solidity,金融,区块链,智能合约,分布式账本,信任链,去中心化,共识算法)