Page 1 of 1 1
Topic Options
#81842 - 2003-09-09 05:59 PM DecToBin() and BinToDec()
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
we already have the dectohex version... the binary versions would be handy.

especially for things like: IP comparisons and subnet matching
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#81843 - 2003-09-10 09:44 AM Re: DecToBin() and BinToDec()
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4945
Loc: Leatherhead, Surrey, UK
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.

Top
#81844 - 2003-09-12 11:40 PM Re: DecToBin() and BinToDec()
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11162
Loc: Boston, MA, USA
BaseConvert already exist as a UDF. The UDF is a result of one of the KiXGolf tournaments. See BaseConverter() - for base2-base36 conversions
_________________________
There are two types of vessels, submarines and targets.

Top
#81845 - 2003-09-15 10:37 AM Re: DecToBin() and BinToDec()
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4945
Loc: Leatherhead, Surrey, UK
How well does it handle negative values?
Top
#81846 - 2003-09-15 02:14 PM Re: DecToBin() and BinToDec()
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
quote:

How well does it handle negative values?

Probably needs to have an ABS() thrown in there before conversion..

Kent
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#81847 - 2003-09-15 03:52 PM Re: DecToBin() and BinToDec()
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4945
Loc: Leatherhead, Surrey, UK
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.

Top
#81848 - 2003-09-15 11:16 PM Re: DecToBin() and BinToDec()
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11162
Loc: Boston, MA, USA
My timezone offsets are stored as positive/negative offsets in minutes. However, I do retirve the offset via WMI.
_________________________
There are two types of vessels, submarines and targets.

Top
Page 1 of 1 1


Moderator:  Lonkero, ShaneEP, Jochen, Radimus, Glenn Barnas, Allen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 142 anonymous users online.
Newest Members
KatieQuinn, Brennnnn, MKubicsek, xguixa, mdress
17681 Registered Users

Generated in 0.033 seconds in which 0.013 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org