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 8283571
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T10:46:41+00:00 2026-06-08T10:46:41+00:00

So i am working on replacing a legacy app that was written in c++

  • 0

So i am working on replacing a legacy app that was written in c++ and i have hit a small issue in mapping a struct used in network communications to c#. Basically the other end on the tcp connection uses the following struct to write dates and i have no idea how to convert the bytes generated by serialising that struct to a c# datetime. Most of it is easy till you get to the “millis” and “second” which are made up of 10 bits and 6 bits respectively so that the 2 bytes is shared between them. I assume you solve this with bit-shifting to read and write the values to a byte array but i have no experience with this.

typedef struct DATE_TIME
{
    USHORT  year;
    UCHAR   month;
    UCHAR   day;
    UCHAR   hour;
    UCHAR   minute;
    USHORT  millis : 10;
    USHORT  second : 6;
}

Code for current attempt to read

ushort Year = br.ReadUInt16();
byte Month = br.ReadByte();
byte Day = br.ReadByte();
byte Hour = br.ReadByte();
byte Minute = br.ReadByte();

ushort secAndMillSec = br.ReadUInt16();
ushort Milliseconds = (ushort)(secAndMillSec >> 6);
ushort Seconds = (ushort)((ushort)(secAndMillSec << 12)>>12);

Code for my first try at a write

 bw.Write(Year);
 bw.Write(Month);
 bw.Write(Day);
 bw.Write(Hour);
 bw.Write(Minute);

 ushort secAndMillSec = (ushort)(Milliseconds << 6);
 secAndMillSec = (ushort)(secAndMillSec + Seconds);
 bw.Write(secAndMillSec);

Again does it look right? So far all the test data i can run it against is empty dates so i am having issues testing myself

  • 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-08T10:46:43+00:00Added an answer on June 8, 2026 at 10:46 am

    Bit fields are not portable across compilers but we can assume that these two fields are in two consequent bytes.

    I assume you are receiving a stream from the network, and you are at the point of reading the datetime.

    BinaryReader reader = new BinaryReader(networkStream);
    int year = reader.ReadUInt16();
    int month = reader.ReadByte();
    int day = reader.ReadByte();
    int hour = reader.ReadByte();
    int minute = reader.ReadByte();
    int ms = reader.ReadUInt16();
    int second = ms >> 10;
    int millist = ms & 1023;
    DateTime dt = new DateTime(year, month, day, hour, minute, second, millis);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Working with Reporting Services 2008 r2. So here's my issue: We have 5 reports
Here is a little background information. I'm working on replacing a dll that has
So, my problem is this. I have a legacy MySQL database that I'm building
I have everything working from the tutorial, replacing it with my data, but it
I'm currently working on replacing a legacy system with JAXB and I'm running into
Working on a legacy application at the moment and we are replacing the data
Everything was working fine in my app. Then, I did a small refactoring and
I'm working on an XML that lists regexs that are to be used as
Recently I was working on implementing a small snippet that caches my results and
I'm working on responsive version of new app and recognised that when page is

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.