What is the basic concept of bytes
This article mainly explains "what is the basic concept of bytes". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what is the basic concept of bytes".
Environment description: Ide: online remix Solidity IDE
Language: solidity solidity
Version number: 0.4.20
Sample code:
Pragma solidity ^ 0.4.20 position contract Test {bytes1 bt1 = "a"; / / byte equivalent bytes1 bytes2 bt2 = "ab"; function getbBytes () public constant returns (bytes1,bytes2) {return (bt1,bt2);} function getbBytesLength () public constant returns (uint,uint) {return (bt1.length,bt2.length);}}
The number 1 after bytes1 indicates that 1 byte bytes is equal to bytes1 by default
The number 2 after Bytes2 represents 2 bytes.
The number 3 after Bytes3 indicates 3 bytes.
The number 4 after bytes4 indicates 4 bytes.
Code parsing:
Bytes1 bt1 = "a"
Bytes2 bt2 = "ab"
Declaration defines two bytes variables, bt1 and bt2, with values of an and ab, respectively
Function getbBytes () public constant returns (bytes1,bytes2):
The function named getbBytes returns two values of type bytes1,bytes2,solidity, like golang, can return multiple values as the function returns
Return (bt1,bt2)
Two values are returned. Note that the value returned here will be expressed as ASCII. The next section will talk about type conversion.
Function getbBytesLength () public constant returns (uint,uint):
Returns the length of two bytes types using the length attribute: return (bt1.length,bt2.length)
Thank you for your reading, the above is the content of "what is the basic concept of bytes", after the study of this article, I believe you have a deeper understanding of what the basic concept of bytes is, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!