Skip to content

[Question] Unexpected results #17

@mantielero

Description

@mantielero

I have the following in python:

import struct

a = 0x95006c08 
print( a & 0x3FF )           # First: 10 bits  --> 8
print( (a >> 10) & 0x1FFF )  # Second: 13 bits --> 27

And I am trying to do the equialent with binaryparse:

import binaryparse
import streams

createParser(p):
  10: a
  13: b 

var 
  a = 0x95006C08 
  s = newStringStream()

s.write(a)
s.setPosition(0)

var tmp = p.get(s)
echo tmp.a  # --> 33 (instead of 8)
echo tmp.b  # --> 2688 (instead of 27)

What am I doing wrong? I am looking to replicate python's results.

By the way, binaryparse is AWESOME. I love it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions