SOLVED: How to perform bit operations on a variable

Home Forums General Programming SOLVED: How to perform bit operations on a variable

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #117286
    EnzoF04
    Participant
      • Topics: 17
      • Replies: 102
      • Total: 119
      • ★★

      I’ve put a value of a component in a variable. I want to alter the value of the variable by shifting bits.

      Let’s say I’ve got a value of decunak 15. When I express decimal 15 in binary it is 0 0 0 0 1 1 1 1. My synthesizer accepts for a specific parameter decimal 15 as 0 0 0 1 1 1 1 0, which is in decimal 30. So I have to shift bits 4-7 one position to the left.

      I’ve thought it to be in a function like:

      function myBitShift(bits, positions, value)
      
      -- bits = how many bits to be shifted
      -- positions = how many positions to be shifted
      -- value = the decimal value that has to be altered via a someValue = someModulator:getModulatorValue()
      
      	local i
      	for i = bits, 1 do 
      		local shftValue = bit.lshift(value(i+1),positions)
      	end
      end

      How can I get this to work? Many thanks for all help!

      • This topic was modified 4 years ago by EnzoF04.
      • This topic was modified 4 years ago by EnzoF04.
      #117304
      EnzoF04
      Participant
        • Topics: 17
        • Replies: 102
        • Total: 119
        • ★★

        Tedjuh helped me with the correct code, I had to use tonumber to convert the data coming from a modulator value.

        
        bit.lshift(tonumber(modVcoValue),1)
      Viewing 2 posts - 1 through 2 (of 2 total)
      • The forum ‘Programming’ is closed to new topics and replies.
      There is currently 0 users and 50 guests online
      No users are currently active
      Forum Statistics
      Threads: 2,495, Posts: 17,374, Members: 77,605
      Most users ever online was 12 on January 22, 2019 3:47 pm
      Ctrlr