PowerShell / PowerShell-IoT

Interact with I2C, SPI & GPIO devices using PowerShell Core!
https://www.powershellgallery.com/packages/Microsoft.PowerShell.IoT
MIT License
130 stars 28 forks source link

Convert-FromBinary function #36

Closed DanielSSilva closed 6 years ago

DanielSSilva commented 6 years ago

Since this module communicates with hardware and hardware uses a lot of binary "communication", it could make it easier (and more readable) to understand the "low-level" code if we had a function that would convert our binary value to an int. For what I've searched, there is no powershell native function to do so. For example, if I see that a register needs the following value: 0001 1010 I can create as $value = 0x1A, or $value = 26. The suggestion would be something like : $value = Convert-FromBinary '0001 1010' Do you think that this would be useful?

tomlarse commented 6 years ago

This already exists in Powershell/.NET, you can for instance use

$value = "11010100"
$convertedbits = [convert]::toint32($value,2)

And send to the register on the device.

DanielSSilva commented 6 years ago

Oooh... I didn't know that. I'm sorry, and thank you!