Skip to content

Instantly share code, notes, and snippets.

@ArslanKathia
Created January 26, 2023 17:28
Show Gist options
  • Select an option

  • Save ArslanKathia/6f4e3dae364ebf6f0bf2f8ad13fccb04 to your computer and use it in GitHub Desktop.

Select an option

Save ArslanKathia/6f4e3dae364ebf6f0bf2f8ad13fccb04 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.7+commit.e28d00a7.js&optimize=false&runs=200&gist=
//SPDX-License-Identifier: MIT
pragma solidity ^0.8;
contract Bytes{
//dynamic bytes
bytes public temp;
constructor(){
temp = "123445asvbvasdas";
}
function pushElement() public{
temp.push('c');
}
function popElement() public{
temp.pop();
}
function getDynamicArrayLength() public view returns(uint){
return temp.length;
}
function getElement(uint _idx) public view returns(bytes1){
return temp[_idx];
}
//bytes can saved 2 hex decimal value
//1 bytes= 8 bit
//1 hex = 4 bit ;; 1 bytes = 2 hex
//fixed size
bytes5 public temp1;
bytes10 public temp2;
function setValue() public{
temp1 = '12345';
temp2 = 'abcedefgas';
}
function getValueTemp1() public view returns(bytes5){
return temp1;
}
function getValueTemp2() public view returns(bytes10){
return temp1;
}
function getLength() public view returns(uint){
return temp1.length;
}
function getDigit(uint _x)public view returns(bytes1){
return temp1[_x];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment