• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!
  • 2026 staff recruitment is open! Check it out and consider applying!

NPC whos able to change DEC value to BIN one

Ist

New Member
Joined
Sep 13, 2010
Messages
181
Reaction score
2
Hey fellows,
I have a homework from my college, I am in need of making a program in C++ or any different language that is changing the IP adress choosen by user (e.g. 192.168.0.1) to a BIN one so 192.168.0.1 = 11000000.10101000.00000000.00000001 :)

I think I am able to do it in C++ but I want to take some fun from that, so I am thinking about making a NPC whos changin it on a player request:DDD

Is there anyone who is able to make such a thing so he can help me with that?;d
w'd be awesome, the A mark guaranteed I suppose
 
I found it on polish forum. Change dec to bin.
LUA:
math.dtb = function(decint)
	local binStr = ""
	repeat
		local mod = decint%2
		binStr = binStr .. (mod ~= 0 and "1" or "0")
		decint = math.floor(decint/2)
	until decint == 0
return binStr:reverse()
end
LUA:
function changeIPtoBIN(ip_str)
 local ip = string.explode(ip_str, '.')
 for i= 1, #ip do
  ip[i] = math.dtb(ip[i])
 end
 return table.concat(ip, '.')
end

EDIT:
rest of polish post [translated]:
Code:
math.dth(decNumber) -- convert dec to hex (parameter is number, return string)
tonumber(hexString) -- default LUA function, convert hex to dec
math.dtb(decNumber) -- convert dec to bin (parameter is number, return string)
math.btd(binString) -- convert bin to dec (parameter is string, return number)
LUA:
math.dth = function(decint)
	local hex, strHex = "0123456789ABCDEF", ""
	repeat
		local mod = decint%16+1
		strHex = strHex .. hex:sub(mod, mod)
		decint = math.floor(decint/16)
	until decint == 0
return "0x" .. strHex:reverse()
end
math.dtb = function(decint)
	local binStr = ""
	repeat
		local mod = decint%2
		binStr = binStr .. (mod ~= 0 and "1" or "0")
		decint = math.floor(decint/2)
	until decint == 0
return binStr:reverse()
end
math.btd = function(binstr)
	local out = 0
	binstr = binstr:reverse()
	for i=binstr:len(), 1, -1 do
		out = out + (tonumber(binstr:sub(i,i))*(2^(i-1)))
	end
return out
end

NOT TESTED
 
Last edited:
cool, here's my decimal to binary lua function:
LUA:
function Dec2Bin(v)
	local n, ret = tonumber(v), ''
	if not n or n < 0 then
		return
	end

	while n > 0 do
		ret = n % 2 .. ret
		n = math.floor(n / 2)
	end

	if ret:len() <3 then
		ret = ('0'):rep(3 - ret:len()) .. ret
	end
	return ret
end
 
Thanks I finally tried and I get used of it, added a few things like you're getting error if you're entering less/more of 8 numbers or if you are enterning characters:)
 

Similar threads

Back
Top