getbyte()

Home Forums General Programming getbyte()

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #385
    netchose
    Participant
    • Topics: 15
    • Replies: 70
    • Total: 85

    i would like to get a byte from block , convert the value to decimal and convert it in ascii

    i don’t understand why it doesn’t work

    thanks

    [code:1v7u5qa0]function Hex2Dec(sValue)

    return tonumber(sValue, 16).."";

    end

    function assignValues(midiMessage)

    programData = midiMessage:getLuaData():getRange(81,18) –ok in the console

    v=programData:getByte(2)
    v1=Hex2Dec(v)
    console (string.char(v1))

    end[/code:1v7u5qa0]

    #3005
    atom
    Keymaster
    • Topics: 159
    • Replies: 2945
    • Total: 3104
    • ★★★★★

    i have no idea why are you trying to convert anything to decimal ? it’s all the same numbers the conversion only makes sense if you want to display the number as DEC or HEX, otherwise it’s the same value (the same memory).

    [code:logyijrq]
    >>> v=64
    >>> console (string.format ("ascii=%c", v))
    ascii=@
    [/code:logyijrq]

    this works and won’t cause problems,however the value needs to represent an ascii character that is printable otherwise you won’t see anything (here is the ascii table http://www.asciitable.com/)

    #3006
    netchose
    Participant
    • Topics: 15
    • Replies: 70
    • Total: 85

    the byte i get has a value of 79 in hexa
    in dec = 121
    console (string.char(121)) – y the result i would like

    it is why i lould like to convert this 79 hexa value

    something which could help : how to diplay v in the console

    [code:3plijlm4]function assignValues(midiMessage)

    lastSavedProgram = midiMessage:getLuaData()
    programData = midiMessage:getLuaData():getRange(81,18)
    unpackedData = utils.unpackDsiData(programData)

    v=programData:getByte(1)

    console (v) — nok
    console (v:toString()) –nok
    console (v:toHexString(1)) –nok

    end[/code:3plijlm4]

    #3007
    Filch
    Participant
    • Topics: 22
    • Replies: 173
    • Total: 195
    • ★★

    console(string.format("v = %d", v))

    #3008
    netchose
    Participant
    • Topics: 15
    • Replies: 70
    • Total: 85

    it’s ok thanks a lot <img loading=” title=”Smile” />

Viewing 5 posts - 1 through 5 (of 5 total)
  • The forum ‘Programming’ is closed to new topics and replies.
There is currently 0 users and 68 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