Radimus
|
(KiX Supporter)
|
2003-09-09 05:59 PM
|
|
|
|
|
DecToBin() and BinToDec()
|
|
we already have the dectohex version... the binary versions would be handy.
especially for things like: IP comparisons and subnet matching
|
|
Re: DecToBin() and BinToDec()
|
|
Why limit it to a particular base?
code:
$iNewValue=BaseConvert($iOldValue,CurrentBase,RequiredBase, Optional WordSize)
The Optional WordSize would be required to deal with negative numbers and overflows.
|
|
Re: DecToBin() and BinToDec()
|
|
BaseConvert already exist as a UDF. The UDF is a result of one of the KiXGolf tournaments. See BaseConverter() - for base2-base36 conversions
|
|
Re: DecToBin() and BinToDec()
|
|
How well does it handle negative values?
|
Kdyer
|
(KiX Supporter)
|
2003-09-15 02:14 PM
|
|
|
|
|
Re: DecToBin() and BinToDec()
|
|
quote:
How well does it handle negative values?
Probably needs to have an ABS() thrown in there before conversion..
Kent
|
|
Re: DecToBin() and BinToDec()
|
|
Heh, no, that actually ignores the issue
What I'm talking about is (for example) binary representation of a negative number. Normally twos-complement - I don't think ones-complement is much used.
For example the offset for time zones is sometimes negative, which is stored in the registry as a twos-complement value.
That's why in my recommendation there is an optional word size - you need to know how wide the target is to construct a twos-complement value.
|
|
Re: DecToBin() and BinToDec()
|
|
My timezone offsets are stored as positive/negative offsets in minutes. However, I do retirve the offset via WMI.
|