Skip to Content
Mastering Blockchain Programming with Solidity
book

Mastering Blockchain Programming with Solidity

by Jitendra Chittoda
August 2019
Intermediate to advanced
486 pages
13h 52m
English
Packt Publishing
Content preview from Mastering Blockchain Programming with Solidity

Understanding the bytes data type

The bytes data type in Solidity is a dynamically sized byte[] array. As it's dynamic sized, the length of this type can grow and shrink. The bytes type is a bit different from bytes1 , bytes2, ... bytes31, and bytes32 types (stepping 1), as bytes stores tightly packed data, whereas bytesN does not. 

The bytes type variables are initialized with an empty string. If you check with the Remix IDE, it will return 0x, meaning a byte[] array with a length of 0.

There is no operator supported directly on bytes, but sometimes you might need to compare the two bytes variables. To check equality, you can compute the keccak256 hash of both the variables and perform a comparison, like that shown in following code example: ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mastering Ethereum

Mastering Ethereum

Andreas M. Antonopoulos, Gavin Wood
Complete Cryptocurrency and Blockchain Course | Learn Solidity

Complete Cryptocurrency and Blockchain Course | Learn Solidity

Ravinder Deol, Codestars By Rob Percival, Thomas Wiesner

Publisher Resources

ISBN: 9781839218262Supplemental Content