|
Qaiia Wanderer
Joined: 06 Apr 2007 Posts: 59
|
Posted: 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?
|
|
|
|
Tech GURU
Joined: 18 Oct 2000 Posts: 2733 Location: Atlanta, USA
|
Posted: 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! |
|
|
|
Taz GURU
Joined: 28 Sep 2000 Posts: 1395 Location: United Kingdom
|
Posted: Fri Apr 13, 2007 11:04 pm |
Take a look at the Finished MUD Scripts forum and in particular at topic 24033!
|
|
_________________ Taz :) |
|
|
|
Qaiia Wanderer
Joined: 06 Apr 2007 Posts: 59
|
Posted: 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.
|
|
|
|
Qaiia Wanderer
Joined: 06 Apr 2007 Posts: 59
|
Posted: 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)))} |
|
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: 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. |
|
|
|
Qaiia Wanderer
Joined: 06 Apr 2007 Posts: 59
|
Posted: Mon Apr 16, 2007 12:07 am |
That worked perfectly. I forgot to say thank you. :)
|
|
|
|
|
|