Synopsis: $getdec()
This is a simple mIRC calculator that will convert the binary input into a decimal value. I wrote this to show how simple a formula for this really is, without using the built-in $base() function of mIRC. Obviously, there is room for improvement, and this may help anyone looking for a loop solution on how to convert these values from one to the other.
Enjoy!
alias getdec {
; First we set our variables:
; %s = The binary value that the user wishes to convert
; %c = We set this at 1 to start. It is the counter to keep track of the looping.
; It will also lend itself to pulling the mid count binary number from the
; string, %s
; %l = The length of the binary start value. We will use this to also calculate
; our exponent value along the way, while decreasing its value during every loop
; %m = This value begins at the length of the input binary number, %s, minus a
; single value. The reason for this is that we want to multiply our current looped
; value, %cur, by the value 2 with an exponent of %m
; %cur = Starts off empty, but eventually this will hold the currently cycled number
; from the binary string, %s
; %v = Also starts off empty, but this will be our returned value from each loop and
; each proper calculation
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
var %s = $1, %c = 1, %l = $len(%s), %m = $calc(%l - 1), %cur, %v
; A little error checking. If %s is not a number, it will not continue
if (%s isnum) {
; If %s is 0, return 0 because no calculations need to be made on any combination of
; 0's
if (!%s) { return 0 }
; Our loop: As long as %c, our counter, is less than or equal to %l, the length of our
; binary string, we continue the loop
while (%c <= %l) {
; We set the currently cycled value, %cur, of our string, %s
%cur = $mid(%s,%c,1)
; If the currently cycled value is not 0, perform our calculation
if (%cur) { %v = $calc(%v + $calc(%cur * $calc(2 ^ %m))) }
; Decrease the mid value, %m, and increase our counter, %c
dec %m
inc %c
}
; Return our calculated decimal value
return %v
}
}
Hey, man! Over the past month and a half I've slowly been getting back into it. I was hanging on IRC and noticed another snippet for doing this via the internet (although mIRC has the base function built-in) and decided to do it all mIRC.
Anyways, how ya doin', man? Haven't talked to you in forever! My fault :-D
Yea, that's CRAZY cool about submitting this like 10 years after my first. I was actually JUST talking about that, like Yawhatnever mentioned.
You did? haha, hilarious, okay I'll remove it.
As for what you're doing, that's good to hear! Glad that you're keeping busy doing what you love! I've been getting back into the design business as well, but nothing solid yet (still trying to find the best CMS for clients to update their sites; I think Concrete5 is going to be my choice).
Drupal is really awesome, but I think it's going to be too much for what I have in mind. I'm building mostly local business sites, and I want the owners to have some bare-minimum control over the content (eg: posting news, new products/services, etc). I don't want to pull my email or get cell phone calls/texts of an "Oops, I deleted [xxxxxx]" nature ;)
You know that Drupal was created by the founding member of ProjectX, right? (The old scripting team I was a part of). Dries Buytaert, I think that's how you spell his name. I remember when he first started working on Drop/Drupal, it was a crazy idea at the time.
Wow, I just noticed this was posted just over 10 years after your first snippet.