Giter Club home page Giter Club logo

Comments (4)

arobenko avatar arobenko commented on June 21, 2024 1

Hi @bearbattle,
I think your mental model of the bitfields as well as endian setting is incorrect.

When you specify members of the <bitfield> the order of the members is starting with the LSB first, so when you think of your AnnFlags as a 16 bit number representation it is encoded as:

MSB -> [PXNum (4 bits) | UnitNum (4 bits) | Flags (8 bits)] <- LSB

The bit ordering of the <set> is also always starting from LSB, i.e bit 0 has mask 0x1 (1 << 0), bit 1 has mask 0x2 (1 << 1), bit 2 has mask 0x4 (1 << 2), etc...

In other words, if your Flags.F is set to 1, UnitNum is set to 2, and PXNum is set to 3, then the 16 bit of the AnnField is going to be 0x3201.

The endian specifies the order of written bytes, not bits, i.e the two bytes above can be written in only 2 ways:

  • 0x32 0x01 - for big endian
  • 0x01 0x32 - for little endian

That's all. If you need to serialize it in different way, then you need to re-order your <bitfield> and/or use different idx property value for your bits. For example if you need your bit F to come first (be MSB), then it needs to have idx="7".

Hope it helps.
Regards,
Alex

from commsdsl.

bearbattle avatar bearbattle commented on June 21, 2024

Thank you. Will the library provide any methods to alter the bit order (i.e. from MSB to LSB)?

from commsdsl.

arobenko avatar arobenko commented on June 21, 2024

Hi @bearbattle,
Counting (indexing) bits from MSB is NOT a common practice in software engineering. I do not intend to do it. It will introduce too much complexity with too little benefit. Re-ordering of the bits is completely within your control when defining the protocol schema, just assign appropriate idx value, such as

<set name="Flags" ...>
    <bit name="F" idx="7" />
    <bit name="K" idx="6" />
    <bit name="P" idx="5" />
    <bit name="C" idx="4" />
</set>

Note that the order of the <bit>-s definition doesn't have to be from lowest idx to the highest. It can be arbitrary, what important is setting the right idx value.

from commsdsl.

bearbattle avatar bearbattle commented on June 21, 2024

Thanks for your reply! I'm closing the issue.

from commsdsl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.