Added Builtin Voltage (#7850)

* Added Builtin Voltage

* Update builtin_voltage.py

* Update electronics/builtin_voltage.py

Co-authored-by: Caeden Perelli-Harris <caedenperelliharris@gmail.com>

* Update electronics/builtin_voltage.py

Co-authored-by: Caeden Perelli-Harris <caedenperelliharris@gmail.com>

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Apply suggestions from code review

Co-authored-by: Caeden Perelli-Harris <caedenperelliharris@gmail.com>

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Create elf.py

Co-authored-by: Caeden Perelli-Harris <caedenperelliharris@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
This commit is contained in:
sadiqebrahim
2022-10-30 17:22:20 +05:30
committed by GitHub
parent ab9d8f3874
commit 94b51f6a91
2 changed files with 73 additions and 8 deletions

View File

@ -2,19 +2,17 @@ def elf_hash(data: str) -> int:
"""
Implementation of ElfHash Algorithm, a variant of PJW hash function.
Returns:
[int] -- [32 bit binary int]
>>> elf_hash('lorem ipsum')
253956621
"""
hash = x = 0
hash_ = x = 0
for letter in data:
hash = (hash << 4) + ord(letter)
x = hash & 0xF0000000
hash_ = (hash_ << 4) + ord(letter)
x = hash_ & 0xF0000000
if x != 0:
hash ^= x >> 24
hash &= ~x
return hash
hash_ ^= x >> 24
hash_ &= ~x
return hash_
if __name__ == "__main__":