funkey Posted February 22, 2012 Share Posted February 22, 2012 Hello. Try this please: Local $iLen = StringLen("00") / 2 ConsoleWrite($iLen & @CRLF) ConsoleWrite(Hex($iLen, 4) & @CRLF) ;result is 0 ?? ConsoleWrite(Hex(Int($iLen), 4) & @CRLF) ConsoleWrite(Hex(1, 4) & @CRLF) Is this a bug or is it just for me? Without division it works!? Programming today is a race between software engineers striving tobuild bigger and better idiot-proof programs, and the Universetrying to produce bigger and better idiots.So far, the Universe is winning. Link to comment Share on other sites More sharing options...
BrewManNH Posted February 22, 2012 Share Posted February 22, 2012 This is what I get when I omit the ,4 in the second consolewrite, which shows that 2/2 in floating point notation is different than 2/2 in integer notation.13FF000000000000000010001 If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
funkey Posted February 22, 2012 Author Share Posted February 22, 2012 I found this in the documentation, so I know now why this is as it is (but I don't like it).Changed: Hex() detects doubles internally and processes them respecting binary format. Programming today is a race between software engineers striving tobuild bigger and better idiot-proof programs, and the Universetrying to produce bigger and better idiots.So far, the Universe is winning. Link to comment Share on other sites More sharing options...
Mat Posted February 22, 2012 Share Posted February 22, 2012 What would you rather it do? Truncate the data? Actually, what it should do is simplify the result of any operations like division, so that double values that are actually integral are cast automatically to integers. AutoIt Project Listing Link to comment Share on other sites More sharing options...
Valik Posted February 22, 2012 Share Posted February 22, 2012 Actually, what it should do is simplify the result of any operations like division, so that double values that are actually integral are cast automatically to integers.No. That's not a good idea for general usage and may not be the desired behavior some of the time. Also, remember, an Int() cast function exists for a reason and will correctly account for some deviation due to floating point inaccuracies. It's also a performance impediment since detecting whole floating point numbers takes a couple steps and can be error-prone without accounting for representation inaccuracies. Detecting those inaccuracies adds additional steps. Link to comment Share on other sites More sharing options...
BrewManNH Posted February 22, 2012 Share Posted February 22, 2012 Totally talking out my ass here because I am no programmer, but when doing a division, couldn't you do something equivalent to a Mod(x,y) to see if the number to be returned is a whole number or not? That way you could do FP math or not depending upon the return. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
Valik Posted February 22, 2012 Share Posted February 22, 2012 Division is not a cheap operation. You do not want AutoIt to do a mod, conditional test and then possibly a second division. If a user is so concerned about getting a floating point result then they should pre-cast their values or cast the result. Remember, it's AutoIt's job to make your life easier but it can't read your mind and judge your intent. Sometimes it needs help and that's why we provide cast functions so you gain fine control over what happens. Link to comment Share on other sites More sharing options...
funkey Posted February 24, 2012 Author Share Posted February 24, 2012 Next problem: How can I do this right? $sData = "0x43E77762000004180101" $iDB = Int(BinaryMid($sData, 7, 2)) ConsoleWrite($iDB & @CR) ;wrong $sDB = BinaryMid($sData, 7, 2) ConsoleWrite($sDB & @CR) ConsoleWrite(Int($sDB) & @CR) ;wrong ConsoleWrite(Int("0x0418") & @CR) ;solution that I want! Programming today is a race between software engineers striving tobuild bigger and better idiot-proof programs, and the Universetrying to produce bigger and better idiots.So far, the Universe is winning. Link to comment Share on other sites More sharing options...
Valik Posted February 24, 2012 Share Posted February 24, 2012 Format your input right. Integers are stored as little endian but your input data has them ordered for big-endian. Here's your example modified to put the data in little-endian format. Local $sData = "0xE7436277000018040101" Local $sDB = BinaryMid($sData, 7, 2) ConsoleWrite($sDB & @CR) ConsoleWrite(Int($sDB) & @CR) ;wrong ConsoleWrite(Int("0x0418") & @CR) ;solution that I want! Remember, you are working with raw bits when you use Binary functions. Link to comment Share on other sites More sharing options...
wraithdu Posted February 24, 2012 Share Posted February 24, 2012 Another solution to get the value you are looking for (whatever its significance in integer form may be): $sData = "0x43E77762000004180101" $iDB = Int(String(BinaryMid($sData, 7, 2))) ConsoleWrite($iDB & @CR) ;better Link to comment Share on other sites More sharing options...
funkey Posted February 25, 2012 Author Share Posted February 25, 2012 Thanks Valik anmd wraithdu. @Valik: Data comes from big endian machine (PLC), so I cannot change the format. @wraithdu: Thanks for this solution. I found it out by my own right after posting, but had no time for editing the post. Now I know that the binary functions do not return strings, they just look like some! Programming today is a race between software engineers striving tobuild bigger and better idiot-proof programs, and the Universetrying to produce bigger and better idiots.So far, the Universe is winning. Link to comment Share on other sites More sharing options...
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