generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: roblox y u have no working base tonumber

Previous Thread :: Next Thread 
Parthax is not online. Parthax
Joined: 27 Apr 2011
Total Posts: 6941
03 Sep 2013 02:58 PM
print(tonumber(7, 2)) --attempt to print 7 as binary
> nil
greater than 2, so why not carry numbers?
this happens for every number less than ten, for every base less than 9.

y u do dat, and if i'm being just an absolute moron while typing this, forgetting something, someone please correct me



cнecĸмαтe, ɴooвѕ.
Report Abuse
blocco is not online. blocco
Joined: 14 Aug 2008
Total Posts: 29474
03 Sep 2013 03:00 PM
heh

thats funny
Report Abuse
Notunknown99 is not online. Notunknown99
Joined: 05 Sep 2008
Total Posts: 25360
03 Sep 2013 03:03 PM
print(tonumber("111", 2))

> 7

Do you even binary?
Report Abuse
stravant is not online. stravant
Forum Moderator
Joined: 22 Oct 2007
Total Posts: 2893
03 Sep 2013 03:19 PM
Do you realize what you just asked?

"print(tonumber(7, 2)) --attempt to print 7 as binary"

Consider this:
local a = tonumber(7,2)
local b = tonumber(7,3)
print(a, b, a+b, a+b-a, b+a-b)

What should that print statement print if things worked as you were expecting? Whenever you're trying to do something, and trying to figure out how it might work, consider the implications of it working a given way.
Report Abuse
Parthax is not online. Parthax
Joined: 27 Apr 2011
Total Posts: 6941
03 Sep 2013 03:38 PM
If lua worked as the language of optimism, I would expect it to return a single base10 integer for each of the arithmedic print arguments, and each different integer in their own bases. For example, what would work in my book would be:

local a = tonumber(7,2)
local b = tonumber(7,3)
print(a, b, a+b, a+b-a, b+a-b)
> 111, 21, 14, 7, 7


cнecĸмαтe, ɴooвѕ.
Report Abuse
Parthax is not online. Parthax
Joined: 27 Apr 2011
Total Posts: 6941
03 Sep 2013 03:39 PM
and @ notunknown

numbers UNDER 10 would return nil. Read whole post instead of parts please.


cнecĸмαтe, ɴooвѕ.
Report Abuse
blocco is not online. blocco
Joined: 14 Aug 2008
Total Posts: 29474
03 Sep 2013 03:39 PM
the problem is that numbers are always represented in some base X

what we need are baseless numbers
Report Abuse
awsumpwner27 is not online. awsumpwner27
Joined: 03 Sep 2011
Total Posts: 4389
03 Sep 2013 03:47 PM
@blocco

So basically, the pure concept of quantity?

I personally prefer the current Arabic numerals. It's really much simpler.
Report Abuse
stravant is not online. stravant
Forum Moderator
Joined: 22 Oct 2007
Total Posts: 2893
03 Sep 2013 03:51 PM
@Parthax

So, you would like it to store every number along with it's base? That means that for every single number your program used extra space would have to be used to store the base that it's in.

And also it means that doing arithmetic operations on them has a magical effect.

It would also mean that you would require some function to get what base a given number is in.

And you would have ugly effects such as that:
tb[a] = 5
print(tb[b]) --> 5

Even though a and b give different results when printed.

There would be lots and lots of bad implications of doing it that way.
Report Abuse
NINJAKID09 is not online. NINJAKID09
Joined: 27 Aug 2009
Total Posts: 14392
03 Sep 2013 03:55 PM
There's base 16, using string.format:

local number = 255
local hex = string.format("%x",number) -- will be "ff".
Report Abuse
1waffle1 is not online. 1waffle1
Joined: 16 Oct 2007
Total Posts: 16381
03 Sep 2013 05:56 PM
local r="0123456789abcdefghijklmnopqrstuvwxyz"
function tobase(x,n)
if n==1 then return('1'):rep(x)end
local s=''
local a=math.floor(math.log(x,n))
repeat
local b=n^a
local c=math.floor(x/b)+1
x=x-b*c+b
s=s..r:sub(c,c)
a=a-1
until a<0
return s
end

local num=tonumber('\49\52\56\54\53\49\55\56\50\52\48\57')
print(tobase(num,36))

hooray.
Report Abuse
Parthax is not online. Parthax
Joined: 27 Apr 2011
Total Posts: 6941
03 Sep 2013 06:01 PM
hooray.


cнecĸмαтe, ɴooвѕ.
Report Abuse
NINJAKID09 is not online. NINJAKID09
Joined: 27 Aug 2009
Total Posts: 14392
03 Sep 2013 06:24 PM
I just remembered, I have this decimal to binary function I made half a year ago:

function dec2bin(dec,bits)
bits = bits or 8;
local bin = "";
local dec_e = dec;
for i = 1,bits do
local test = math.floor(dec_e % 2);
dec_e = dec_e / 2;
bin = tostring(test) .. bin;
end
return bin;
end
Report Abuse
Parthax is not online. Parthax
Joined: 27 Apr 2011
Total Posts: 6941
03 Sep 2013 06:32 PM
hrey


cнecĸмαтe, ɴooвѕ.
Report Abuse
1waffle1 is not online. 1waffle1
Joined: 16 Oct 2007
Total Posts: 16381
03 Sep 2013 06:33 PM
    function tobinary(x,a)
        local a=a or math.floor(math.log(x,2))
        local b=2^a
        local c=math.floor(x/b)
        return c..(a>0 and tobinary(x-b*c,a-1)or'')
    end
    print(tobinary(42))

hooray.
Report Abuse
NINJAKID09 is not online. NINJAKID09
Joined: 27 Aug 2009
Total Posts: 14392
03 Sep 2013 06:35 PM
@waffle 5010? lol
Report Abuse
xSIXx is not online. xSIXx
Joined: 06 Aug 2010
Total Posts: 9202
03 Sep 2013 06:38 PM
heh heh "roblox"

heh heh "working"
Report Abuse
Notunknown99 is not online. Notunknown99
Joined: 05 Sep 2008
Total Posts: 25360
03 Sep 2013 06:38 PM
...Base 3..?
Report Abuse
Notunknown99 is not online. Notunknown99
Joined: 05 Sep 2008
Total Posts: 25360
03 Sep 2013 06:40 PM
Wait, no. If a = 3 then it returns 5010, a = 2 returns 1010 (Which is not 42 in base 2...)
Report Abuse
1waffle1 is not online. 1waffle1
Joined: 16 Oct 2007
Total Posts: 16381
03 Sep 2013 06:42 PM
a? what? if a isn't math.floor(math.log(x,2)) then you're doing it wrong.
Report Abuse
Notunknown99 is not online. Notunknown99
Joined: 05 Sep 2008
Total Posts: 25360
03 Sep 2013 06:44 PM
Well 42 is not 5010 in base 2.
Report Abuse
1waffle1 is not online. 1waffle1
Joined: 16 Oct 2007
Total Posts: 16381
03 Sep 2013 06:45 PM
42_10=101010_2

    print(tobinary(42))

> 101010
Report Abuse
Notunknown99 is not online. Notunknown99
Joined: 05 Sep 2008
Total Posts: 25360
03 Sep 2013 06:46 PM
> function tobinary(x,a)
local a=a or math.floor(math.log(x,2))
local b=2^a
local c=math.floor(x/b)
return c..(a>0 and tobinary(x-b*c,a-1)or'')
end
print(tobinary(42))
5010
Report Abuse
1waffle1 is not online. 1waffle1
Joined: 16 Oct 2007
Total Posts: 16381
03 Sep 2013 06:47 PM
what kind of crap lua interpreter are you using
Report Abuse
Notunknown99 is not online. Notunknown99
Joined: 05 Sep 2008
Total Posts: 25360
03 Sep 2013 06:48 PM
Roblox...
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image