# Decimal places: data types and Newbie confusion

## Recommended Posts

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,

##### Share on other sites

You just need a quick BitOr() to put the bits in their place. What form is \$variable in: integer, hex string, ...?

```\$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 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

##### Share on other sites

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 by OiMunk

##### Share on other sites

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

## Create an account

Register a new account

×

• Wiki

• Back

• #### Beta

• Git
• FAQ
• Our Picks
×
• Create New...