atoi64

Jim Michaels
Attachments
atoi64.lsm (1246 bytes)

atoi64 - string to 64-bit integer number conversion.

basically a replacement for atoi64() and atou64() except that these functions have a number of features the regular ones don't. very flexible.

  • handles perl number format (with _ before, after, or in between numbers (ignored)), handle 0b for binary, 0d for decimal, 0 in front for octal (I added 0q or 0o for historic reasons), and 0x for hexadecimal
  • handles an optional : suffix followed followed by SI unit such as G or GB or "computer" IEC unit such as Gi or GiB.
  • case insensitive.
  • ignores garbage on end or at beginning as long as it doesn't match something the lexer interprets as meaningful
  • ignores underscores (_).

The 64-bit limit is Exa.
128-bit can handle Yotta and beyond, but there isn't sufficent IEC or SI units that can handle 128-bit numbers.
The Perl module is not on CPAN.

Languages:

perl, autoit3, c++, php, javascript

Future:

  • will be switched and fully coded to 128-bits when that language feature becomes more common - 128-bit provisions are already in there now. maybe I can't get all the languages reeled in, but I will try for as many as I can.
  • I may require BigNum on Perl just to get the large integers. this will give me 128-bit support immediately without having to compile C code for Perl. I would like to see a number handling system that is well-integrated and doesn't require the user to use anything special to use those numbers - only to "use 'packagename';". any helpful hints are appreciated.

License:

GPL3

Author: Jim Michaels
Created: 2007
Current Date: 7/27/2011
Abstract: convert ascii string to signed 64-bit or 63-bit integer.
it ignores underscores(_). string input is case insensitive. it can be hexadecimal: start with 0x, decimal: plain number or start with 0d, octal: start with 0, 0q, 0o, binary: start with 0b, can be appended with SI units :B :K :KB :M :MB :G :GB :T :TB :P :PB :E :EB or computer units :Ki :KiB :Mi :MiB :Gi :GiB :Ti :TiB :Pi :PiB :Ei :EiB as a multiplier. priority will be given to longer suffixes in a stream of printable characters.

integer64 is unsigned and case insensitive. it ignores underscores(_). it can be hexadecimal (start with 0x), decimal (plain number or start with 0d), octal (start with 0, 0q, 0o), binary (start with 0b), and can be appended with SI units (:B :D :DB :H :HB :K :KB :M :MB :G :GB :T :TB :P :PB :E :EB) or computer units (:Ki :KiB :Mi :MiB :Gi :GiB :Ti :TiB :Pi :PiB :Ei :EiB) as a multiplier suffix. priority will be given to longer suffixes in a stream of printable characters.

integer63 is signed and case insensitive. it ignores underscores(_). it can start with a - sign and be negative and be in any of the following number formats: it can be hexadecimal (start with 0x), decimal (plain number or start with 0d), octal (start with 0, 0q, 0o), binary (start with 0b), and can be appended with SI units (:B :D :DB :H :HB :K :KB :M :MB :G :GB :T :TB :P :PB :E :EB) or computer units (:Ki :KiB :Mi :MiB :Gi :GiB :Ti :TiB :Pi :PiB :Ei :EiB) as a multiplier suffix. priority will be given to longer suffixes in a stream of printable characters.

returns a signed or unsigned 64-bit integer or 0 on failure (sorry folks, but not all languages support modifying function arguments).

Downloads

The .lsm file is here: https://sourceforge.net/p/atoi64/home/atoi64/attachment/atoi64.lsm

The downloads are here: http://sf.net/projects/atoi64


Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks