OiMunk Posted January 29, 2008 Share Posted January 29, 2008 I have an 8 digit hex number that I need to alter digit 3 and 4 using a variable, which is then sent to a function. $number=0x00000BB9 _MidiOutShortMsg($open,$number) ;I tried the following: $number=hex(0x00,2) & hex($variable,2) & hex(0x0BB9,4) _MidiOutShortMsg($open,$number) ; but the function received the wrong value, I'm guessing because it's a string and not a number? ; I successfully tried the following, but I'm thinking there must be a better and more efficient way of doing this (efficiency is important with this script) $number = 0x00000BB9 + ($variable*0x10000) ; this works, but... _MidiOutShortMsg($open,$number) ; Is there a better way to solve this? cheers, Link to comment Share on other sites More sharing options...
PsaltyDS Posted January 29, 2008 Share Posted January 29, 2008 (edited) You just need a quick BitOr() to put the bits in their place. What form is $variable in: integer, hex string, ...? Are the bits you are replacing always zeros to start with? If not, you add a little masking with BitAnd() first. $variable = 0xCC $iBase = 0xFEDCABB9 $number = BitAND($iBase, 0xFFF) ; mask off unwanted bits $number = BitOR($number, BitShift($variable, -12)) ; add $variable, shifted left 12 bits into position ConsoleWrite("Debug: $number = 0x" & Hex($number) & @LF) Edited January 29, 2008 by PsaltyDS Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
OiMunk Posted January 30, 2008 Author Share Posted January 30, 2008 (edited) thanks! That should work well, and it's a good excuse to work on my binary math skills... The bits I'm replacing are always zeros, so I won't need to BitAnd, but in the future I may need to. I think $variable[5] must be a string, because I create it as follows: $a=$mox.GetMidiInput() ; GetMidiInput() returns values such as "127,28,1,55,68" $variable= StringSplit($a, ",") cheers, Edited January 30, 2008 by OiMunk Link to comment Share on other sites More sharing options...
PsaltyDS Posted January 30, 2008 Share Posted January 30, 2008 I think $variable[5] must be a string, because I create it as follows: $a=$mox.GetMidiInput() ; GetMidiInput() returns values such as "127,28,1,55,68" $variable= StringSplit($a, ",") Then make sure to convert from string to number: Number($variable[5]) Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law 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