PCode Posted February 26, 2007 Posted February 26, 2007 (edited) So I was testing myself by making a program that would convert Binary to Decimal. Check it out: Do $d = $d / 5 Until ($d < 1) While ($d <> 0) $d = $d * 5 $result = $result + Int($d) MsgBox(0,"Test1",$d & "-" & Int($d) & "=" & ($d - Int($d))) $d = $d - Round($d) MsgBox(0,"Test2",$d) WEnd Basically, $d is the original Binary and $result is going to be the decimal. When I first ran it, It seemed to give me an infinite loop if I did a binary number over 4. That's why I put those Message Boxes in there, to see what's going on. I tried both Round() and Int() and both give me this same problem. Anyway, somehow Test 1 is getting me equations like "1-1=3.2983049823e-18"(not exactly, but you get the picture), where I was expecting 0. Where is that tiny number even coming from? Can I get some help please? Edited February 26, 2007 by PCode
Moderators SmOke_N Posted February 26, 2007 Moderators Posted February 26, 2007 Mind posting an actual example and not some code that can't be ran without us putting our own information in? Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
PCode Posted February 26, 2007 Author Posted February 26, 2007 It's nice to get a quick responce. Attached is the uncompiled version of the script. Just type in 1000 in the binary for an example.
Moderators SmOke_N Posted February 26, 2007 Moderators Posted February 26, 2007 (edited) Does this fix it?#include <GUIConstants.au3> GUICreate("Encoder") $inpBin = GUICtrlCreateInput("Binary",5,5) $inpNorm = GUICtrlCreateInput("Normal",5,30) ;$inpHex = GUICtrlCreateInput("Hexidecimal",5,55) ;$inpNew = GUICtrlCreateInput("Superdecimal",5,80) $btnTransfer = GUICtrlCreateButton("Transfer!!",5,105) GUISetState() While 1 $msg = GUIGetMsg() If $msg == $GUI_EVENT_CLOSE Then Exit If $msg == $btnTransfer Then $nBin = Number(GUICtrlRead($inpBin)) $d = $nBin $result = 0 Do $d = $d / 5 Until ($d < 1) While ($d <> 0) $d = $d * 5 $result = $result + Int($d) MsgBox(0,"Test1",$d & "-" & Int($d) & "=" & ($d - Int($d))) $d = $d - Int($d) MsgBox(0,"Test2",$d) WEnd GUICtrlSetData($inpNorm,$result) EndIf WEnd Edit: I see the numbers are too big... might want to look at autoits limits. Edited February 26, 2007 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
PCode Posted February 26, 2007 Author Posted February 26, 2007 (edited) No. I don't even see how that is different. Edit: Numbers too big? How is that the case? Let's take 1000 Do While 1000 / 5 = 200 / 5 = 40 / 5 = 8 / 5 = 1.6 /5 = 0.32 0.32 * 5 = 1.6 Int(1.6) = 1 1.6-1 = 0.6 .6 * 5 = 3 Int(3) = 3 3 - 3 = 0 (Last time I checked) Nothing over 4 digits. Edited February 26, 2007 by PCode
Moderators SmOke_N Posted February 26, 2007 Moderators Posted February 26, 2007 No. I don't even see how that is different.Edit: Numbers too big? How is that the case? Let's take 1000Do While1000 / 5 = 200 / 5 = 40 / 5 = 8 / 5 = 1.6 /5 = 0.320.32 * 5 = 1.6Int(1.6) = 1 1.6-1 = 0.6.6 * 5 = 3Int(3) = 33 - 3 = 0 (Last time I checked)Nothing over 4 digits.Everything I was trying with Number was failing... but then I remembered a circumstance where someone else ran into an issue... I might just be too tired to answer your question... but I found the thread (unfortunately 3.2.3 isn't released yet)http://www.autoitscript.com/forum/index.php?showtopic=38502 Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now