Most Significant Bit using Binary Search Code | Solidity 0.8

  Рет қаралды 3,806

Smart Contract Programmer

Smart Contract Programmer

Күн бұрын

Code for finding most significant bit using binary search.
Algorithm
• Most Significant Bit w...
Notes
github.com/t4s...
Code
solidity-by-ex...
Take a course
www.smartcontr...
Follow
/ programmersmart
/ discord
t.me/smartcont...
smartcontractp...
#Solidity #SmartContract #Ethereum #スマートコントラクト

Пікірлер: 12
@smartcontractprogrammer
@smartcontractprogrammer 2 жыл бұрын
Algorithm kzbin.info/www/bejne/p6TPp3xtiZuMbKc Notes github.com/t4sk/notes Code solidity-by-example.org/bitwise/ Take a course www.smartcontract.engineer/
@MrCoreyTexas
@MrCoreyTexas 7 ай бұрын
This technique is called unrolling loops. Before I watched the video I implemented it in a do while() loop, then unrolled the loop. It seems to help with gas if you precompute the values 2**128, 2**64, etc. Before I watched your Algorithm video, I was trying to figure out ways to go from bit 4 to bit 6 ((8+4)/2) but the shifting solution is so elegant. Surprised I haven't seen this before!
@MrCoreyTexas
@MrCoreyTexas 7 ай бұрын
If you're used to printf() style debugging I guess you could just make a generic event Log(string) and emit instead of printf, but it still is awkward to read the logs. One suggestion is try implementing the algorithm in your favorite "conventional" language and translate it to Solidity (maybe even with ChatGPT )
@smartcontractprogrammer
@smartcontractprogrammer 7 ай бұрын
I usually do this with Python before writing it in Solidity
@mankorli
@mankorli 2 жыл бұрын
when will the rust samples come
@sweetjimmy
@sweetjimmy 2 жыл бұрын
Hey.. can you please also show the iterative approach to this algorithm?
@smartcontractprogrammer
@smartcontractprogrammer 2 жыл бұрын
kzbin.info/www/bejne/ZpnVd5SXbt1-pLM
@berealmusic
@berealmusic 2 жыл бұрын
Nice
@MrCoreyTexas
@MrCoreyTexas 7 ай бұрын
I used a test vector of 2**256-1 == 115792089237316195423570985008687907853269984665640564039457584007913129639935 to maximize the gas when testing variants
@tuntunewala
@tuntunewala 2 жыл бұрын
Hey sir i just want to ask a question that is it worthy to write a binary search algo in solidity? Doesn't it will take more gas??
@smartcontractprogrammer
@smartcontractprogrammer 2 жыл бұрын
Some contracts on mainnet use binary search to find checkpoints Examples Curve gauge contract Uniswap V3 ticks
@tuntunewala
@tuntunewala 2 жыл бұрын
@@smartcontractprogrammer don't know what are checkpoints but i got you
Call Functions with Key Value Inputs | Solidity 0.8
3:11
Smart Contract Programmer
Рет қаралды 3,2 М.
C can do this too and it's faster than Python
2:09:48
Tsoding Daily
Рет қаралды 6 М.
Don’t Choose The Wrong Box 😱
00:41
Topper Guild
Рет қаралды 62 МЛН
We Attempted The Impossible 😱
00:54
Topper Guild
Рет қаралды 56 МЛН
Beat Ronaldo, Win $1,000,000
22:45
MrBeast
Рет қаралды 158 МЛН
Re-entrancy lock | Vyper 0.4
5:30
Smart Contract Programmer
Рет қаралды 101
Trait as function input and output | Learn Rust part 32
9:01
Smart Contract Programmer
Рет қаралды 135
Use statement | Vyper 0.4
4:59
Smart Contract Programmer
Рет қаралды 40
Don’t Choose The Wrong Box 😱
00:41
Topper Guild
Рет қаралды 62 МЛН