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


Richard H.Administrator
(KiX Supporter)
2003-09-10 09:44 AM
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.


Sealeopard
(KiX Master)
2003-09-12 11:40 PM
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

Richard H.Administrator
(KiX Supporter)
2003-09-15 10:37 AM
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


Richard H.Administrator
(KiX Supporter)
2003-09-15 03:52 PM
Re: DecToBin() and BinToDec()

Heh, no, that actually ignores the issue [Wink]

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.


Sealeopard
(KiX Master)
2003-09-15 11:16 PM
Re: DecToBin() and BinToDec()

My timezone offsets are stored as positive/negative offsets in minutes. However, I do retirve the offset via WMI.