This is our old Q&A Site. Please post any new questions and answers at

In lua,how to get the buffer value.I have to print the value in the value of buffer on console. I have a offset of 2 (2 bytes) and have to print the value of last 10 bits of buffer.

Please help me with this.

asked 20 Apr '15, 12:50

lakshmi's gravatar image

accept rate: 0%

You said you have an "offset of 2 (2 bytes)" - do you mean the value you want to get is the last 10 bits of the first and second bytes of the buffer, or do you mean it's the last 10 bits of the 3rd and 4th bytes?

Something like this:

-- assuming "myproto" is the name of the Proto object
function myproto.dissector(tvbuf, pinfo, root)
    -- for the first and second bytes:
    if tvbuf:len() > 1 then
        local bytes = tvbuf:range(0,2):uint()
        info( string.format("Last 10 bits of 1st and 2nd bytes in hex = %x",, 0x03FF)) )

    -- for the third and fourth bytes:
    if tvbuf:len() > 3 then
        local bytes = tvbuf:range(2,2):uint()
        info( string.format("Last 10 bits of 3rd and 4th bytes in hex = %x",, 0x03FF)) )
permanent link

answered 30 Jun '15, 21:21

Hadriel's gravatar image

accept rate: 18%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:


question asked: 20 Apr '15, 12:50

question was seen: 3,247 times

last updated: 30 Jun '15, 21:21

p​o​w​e​r​e​d by O​S​Q​A