Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » zMUD General Discussion
Qaiia
Wanderer


Joined: 06 Apr 2007
Posts: 59

PostPosted: Fri Apr 13, 2007 9:49 pm   

decimal => binary conversion
 
I need to convert a 10 digit decimal number (eg: 0004194309) into a binary bitfield in order to extrapolate 14 fields of data. zMUD doesn't seem to have any native methods for this conversion. Does anyone have a suggestion?
Reply with quote
Tech
GURU


Joined: 18 Oct 2000
Posts: 2733
Location: Atlanta, USA

PostPosted: Fri Apr 13, 2007 10:16 pm   
 
I guess the simplest thing to do would be to write your own function. I'm about to get on a flight, but if no-one has posted, I'll whip one together for ya.
_________________
Asati di tempari!
Reply with quote
Taz
GURU


Joined: 28 Sep 2000
Posts: 1395
Location: United Kingdom

PostPosted: Fri Apr 13, 2007 11:04 pm   
 
Take a look at the Finished MUD Scripts forum and in particular at topic 24033!
_________________
Taz :)
Reply with quote
Qaiia
Wanderer


Joined: 06 Apr 2007
Posts: 59

PostPosted: Fri Apr 13, 2007 11:06 pm   
 
I'm not even going to begin to fathom why that didn't show up in my search. I'll take a look at that and see if it'll help. Thank you.
_________________
Citrus: The Juicy Alternative
Reply with quote
Qaiia
Wanderer


Joined: 06 Apr 2007
Posts: 59

PostPosted: Sat Apr 14, 2007 12:09 am   
 
Okay, this function suits my needs almost perfectly. However, I need it to return a 28-digit binary number, with leading zeroes filling the extra space. Is there a clean way to modify this function to accomplish that?

Code:
#FUNC dec2bin {%if("%1"!="0",%concat(@dec2bin(%eval(%1/2)),%mod(%1,2)))}
_________________
Citrus: The Juicy Alternative
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Sat Apr 14, 2007 12:39 am   
 
Once you've got your resulting number, you can just do something like:

%concat(%repeat("0",28-%len(%1)),%1)

Even if that doesn't compile properly, I'm sure you get the idea.
Reply with quote
Qaiia
Wanderer


Joined: 06 Apr 2007
Posts: 59

PostPosted: Mon Apr 16, 2007 12:07 am   
 
That worked perfectly. I forgot to say thank you. :)
_________________
Citrus: The Juicy Alternative
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » zMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net