Hex Subtraction
Again this takes the pattern from the binary function and adapts it to work with hex
| 001 002 003 004 005 006 007 008 009 010 011 012 013 014 015 016
| ## this will always subtract value2 from value1 function Get-HexDifference { param( [string]$inputvalue1, [string]$inputvalue2 ) ## check valid hex numbers Test-Hex $inputvalue1 Test-Hex $inputvalue2 $diff = (ConvertTo-Decimal -inputvalue $inputvalue1 -hex) ` - (ConvertTo-Decimal -inputvalue $inputvalue2 -hex) if ($diff -lt 0){Throw "Hex subtraction produces negative number"} else {ConvertTo-Hex -inputvalue $diff} } |
As with the binary subtraction function we test to see if we’ve gone negative – if so reject the value.
That’s the end of the math module for now. As soon as I’ve done the help files I’ll post it on codeplex.