Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8207573
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T09:02:42+00:00 2026-06-07T09:02:42+00:00

I receive a datapacket containing a byte array and I have to get some

  • 0

I receive a datapacket containing a byte array and I have to get some integer values from it.
Here is a part of the documentation. Can someone help me please?

This comes in a 4-byte array.

Year from 1990 to 2052 (6 bit), Month from 1 to 12 (4 bit), Day from 1
to 31 (5 bit), Hour from 0 to 23 (5 bit), Minute from 0 to 59 (6 bit),
Second from 0 to 59 (6 bit) Default value: 1 January 2000, 12:00:00

The format of the message is in little endian.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T09:02:44+00:00Added an answer on June 7, 2026 at 9:02 am

    What you need is some bitwise operations. First, construct an int out of the bytes:

    int n = b[0] | (b[1] << 8) | (b[2] << 16) | (b[3] << 24);
    

    Then, chop up the int into components. Now, your question does not specify which way do the fields go, right-to-left or left-to-right. That question is related to endianness, but not identical. So let’s assume that the fields go from left to right.

    Good sense suggests left-to-right. This way the integer representations of time values can be compared – the significance of year bits is more than month bits etc, so when you compare integers that correspond to two moments in time, you get a chronologically correct result.

    Here’s a mental image for you. This is an integer variable, composed of bits:

    f e d c b a 9 8 7 6 5 4 3 2 1 0
                -----
                  offset is 6, length is 3
    

    Let’s define a function that takes a arbitrary chunk from an int at a given offset (in bits), with a given length (in bits).

    int bits(int n, int offset, int length)
    {
        //shift the bits rightward, so that the desired chunk is at the right end
        n = n >> (31 - offset - length); 
    
        //prepare a mask where only the rightmost `length`  bits are 1's
        int mask = ~(-1 << length);
    
        //zero out all bits but the right chunk
        return n & mask;
    }
    

    Could’ve been a one-liner, but I wanted to make it somewhat instructive. Folks in the answers below effectively inline this function, by specifying the shift factor and the mask by hand for each chunk.

    Now let’s decompose. Assuming n comes from the topmost snippet:

    int year  = bits(n, 0,  6),
        month = bits(n, 6,  4),
        day   = bits(n, 10, 5),
        hour  = bits(n, 15, 5),
        min   = bits(n, 20, 6),
        sec   = bits(n, 26, 6);
    

    We get the values of the offset by combining the total lengths of the previous fields together. This is under the assumption that the fields go left to right; if they go the other way around, the offset values would be different.

    Did that make sense?

    EDIT: if the bit chunks go right to leftt, then here’s how it’d go:

    int sec   = bits(n, 0,  6),
        min   = bits(n, 6,  6),
        hour  = bits(n, 12, 5),
        day   = bits(n, 17, 5),
        month = bits(n, 22, 4),
        year  = bits(n, 26, 6);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Receive activities in WF4 can take two kind of values, Message or Parameters. Does
I receive a get request from server, but is encrypted with a simple algorithm
I have been trying to receive a data packet from a client however during
I receive data in the following format from the server <ul> <li>Some text</li> <li>Other
I receive this date format from facebook and google docs: 2011-02-25T10:55:25+0000 How can I
I receive some arguments into a stored procedure. These arguments are NVARCHAR's. I have
I receive an array from a server which contains objects and association tables. So
I receive a date in the format below from a json file. Im not
I receive messages from a Google Talk account, they are shown in the Table
I receive a string from a database query, then I remove all HTML tags,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.