Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

extracting data from .net Data.ToBinary()

I need to read custom-serialized binary data, written using BinaryWriter class. To store a date, the original designers used BinaryWriter.Write( Data.ToBinary() );

This article sort-of mentions how the ToBinary function works; but what I need, is to build code that will emulate the methods ToBinary() and FromBinary() in other programming languages.

Can anyone look at the following pseudo code and give me an idea of the real offset bit counts.

long i = DateTime.Now.ToBinary();
// will likely need to add code here to "condition" the value
int yr = (i >> 48) & 0x7fff;
int mo = (i >> 44) & 0xf;
int day = (i >> 36) & 0xff;
int hr = (i >> 28) & 0xff;
int min = (i >> 20) & 0xff;
int sec = (i >> 12) & 0xff;
int ms = i & 0xfff;

ps. will this concept even work..or is the date stored in the form of total milliseconds?

like image 676
user697296 Avatar asked Sep 27 '26 12:09

user697296


1 Answers

You can use any format you want, as long as you do both the serialize & deserialize :) But since a common representation is 'Ticks', why not go with that? Serialization is all about saving & restoring, as long as you can restore anything you save, serialization worked :)

like image 116
NKCSS Avatar answered Sep 30 '26 07:09

NKCSS