Announcement

Collapse
No announcement yet.

base_convert — Convert a number between arbitrary bases

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Imagine Programming
    replied
    Originally posted by kingzooly View Post
    That I will sir that I will thank you very much I will enjoy learning from this
    :yes ugh 10-char limit

    Leave a comment:


  • kingzooly
    replied
    Originally posted by Imagine Programming View Post
    There ya go, test this well!
    That I will sir that I will thank you very much I will enjoy learning from this

    Leave a comment:


  • Imagine Programming
    replied
    There ya go, test this well!
    Attached Files

    Leave a comment:


  • Imagine Programming
    replied
    I still have an old base conversion class in PHP which I will try to translate to Lua. It will be improvisation, however it should do the trick for like every possible base.

    One note though, the base.convert I will write will be case sensitive. 4az9 ~= 4Az9.

    Leave a comment:


  • kingzooly
    replied
    Originally posted by Imagine Programming View Post
    explode does the same as split, it will slice a string into pieces based on a specified delimiter. :yes

    As for base_convert, between which bases do you need to be able to convert?
    32 to 10 so far its used a few times so not sure converting it bit by bit at the moment
    and I am sure there is back to 10 from 32 at some point.

    Leave a comment:


  • Imagine Programming
    replied
    explode does the same as split, it will slice a string into pieces based on a specified delimiter. :yes

    As for base_convert, between which bases do you need to be able to convert?

    Leave a comment:


  • kingzooly
    replied
    Originally posted by Imagine Programming View Post
    split is deprecated in PHP and should not be used any more, use explode($pattern, $str).

    Code:
    function explode(div,str) -- credit: http://richard.warburton.it
      if (div=='') then return false end
      local pos,arr = 0,{}
      -- for each divider found
      for st,sp in function() return string.find(str,div,pos,true) end do
        table.insert(arr,string.sub(str,pos,st-1)) -- Attach chars left of current divider
        pos = sp + 1 -- Jump past current divider
      end
      table.insert(arr,string.sub(str,pos)) -- Attach chars right of last divider
      return arr
    end
    From: http://lua-users.org/wiki/MakingLuaLikePhp

    I used to have a base conversion function in Lua somewhere, but I can't seem to find it right now...
    I am converting a script to work in AMS, but if that gives the same result I happly us it

    Leave a comment:


  • Imagine Programming
    replied
    split is deprecated in PHP and should not be used any more, use explode($pattern, $str).

    Code:
    function explode(div,str) -- credit: http://richard.warburton.it
      if (div=='') then return false end
      local pos,arr = 0,{}
      -- for each divider found
      for st,sp in function() return string.find(str,div,pos,true) end do
        table.insert(arr,string.sub(str,pos,st-1)) -- Attach chars left of current divider
        pos = sp + 1 -- Jump past current divider
      end
      table.insert(arr,string.sub(str,pos)) -- Attach chars right of last divider
      return arr
    end
    From: http://lua-users.org/wiki/MakingLuaLikePhp

    I used to have a base conversion function in Lua somewhere, but I can't seem to find it right now...

    Leave a comment:


  • kingzooly
    replied
    Is there a function that mimics the php split functions I have one that someone created but does not work in AMS and then one that says it needs string but php split takes table and string.

    Leave a comment:


  • kingzooly
    replied
    Originally posted by Ulrich View Post
    After a quick search I found this, the script might work as a starting point.

    Ulrich
    I will give this a look over, the problem with others I see do far will only take 2 values not 3 but from what I read of the funtion it was no auto detecting what the base it was given so I was not sure how to use them as they was no documents for them, I give this a look thanks.

    Leave a comment:


  • Ulrich
    replied
    After a quick search I found this, the script might work as a starting point.

    Ulrich

    Leave a comment:


  • base_convert — Convert a number between arbitrary bases

    i am converting a php script to lua but having problems with base_convert — Convert a number between arbitrary bases

    PHP Code:
    string base_convert string $number int $frombase int $tobase 
    what would be the lua version.
Working...
X
😀
🥰
🤢
😎
😡
👍
👎