473,396 Members | 1,816 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

how encode or decode date in binary

Hello Friends

I have a problem date format written as DD/MM/YYYY. Date already save into a file as binary. I don't know which technique should be used. Sample date as following


a. 31/09/2009 in binary in the file written as 4f 75 25 00
b. 31/05/2008 in binary in the file written as 5a 74 25 00

My problem is how the date would be written as above in binary. Also, how encode or decode.

Please help me.

Thanks in advance.
Aug 19 '08 #1
18 8857
weaknessforcats
9,208 Expert Mod 8TB
What was the format of the data when it was written?

Was it:

int month
int slash
int day
int slash
int year

??

Or was it:
int month
char slash
int day
char slash
int year

Or was it:

char month
char month
char slash
char day
char day
char slash
char year
char year
char year
char year

??

You can't read file when you don't know the format of the data.
Aug 19 '08 #2
the date format DD/MM/YYYY meaning

DD -date
slash (/) - just a separator
MM - month
slash (/) - just a separator
YYYY - year

so, data to be taken for decode or encode is DDMMYYYY only

Thanks
Aug 19 '08 #3
the date format DD/MM/YYYY meaning

DD -date
slash (/) - just a separator
MM - month
slash (/) - just a separator
YYYY - year

so, data to be taken for decode or encode is DDMMYYYY only

Thanks
all data must be in INTEGER example given 31052009
Aug 19 '08 #4
weaknessforcats
9,208 Expert Mod 8TB
[quote=saykeenari]
all data must be in INTEGER example given 31052009
[/code]

If you can read 31052009 in the disc file, then you date is a string of char integers.

Further, it means the file is not in binary. If it was, you couldn't read the data directly with your eye.

From what you say, the disc file is in text mode and you need to read the date into a char array. Then you can parse the array and add the slashes.
Aug 19 '08 #5
newb16
687 512MB
all data must be in INTEGER example given 31052009
So, must it be integer (32-bit) 30million-something for day 30 or the same 32 bits in unknown format you gave in first post (4f 75 25 00) ?
Aug 20 '08 #6
So, must it be integer (32-bit) 30million-something for day 30 or the same 32 bits in unknown format you gave in first post (4f 75 25 00) ?
Yes, this in unsigned integer and using 32 bits to save the data. So, I am not sure how or technique used to encode or decode or using bitwise operator as mentioned in my first post. So,it is the main problem.

I hope you can understand it

Thank you
Aug 20 '08 #7
newb16
687 512MB
Yes, this in unsigned integer and using 32 bits to save the data. So, I am not sure how or technique used to encode or decode or using bitwise operator as mentioned in my first post. So,it is the main problem.

I hope you can understand it

Thank you
I understand, but the data provided ( 2 samples ) is not enough to guess how data is encoded, are there any fields where day month and year are stored independently or is it flat ( days since some date ) number.
It seems however that it is low-endian 'days since ***' format ( as first minus second equals 245, that is number of days in year minus 120 days in four months )
So you need to convert it to 32bit integer, find where is zero point of the scale and go.
Aug 20 '08 #8
I understand, but the data provided ( 2 samples ) is not enough to guess how data is encoded, are there any fields where day month and year are stored independently or is it flat ( days since some date ) number.
It seems however that it is low-endian 'days since ***' format ( as first minus second equals 245, that is number of days in year minus 120 days in four months )
So you need to convert it to 32bit integer, find where is zero point of the scale and go.
Oh , I am forgot that the first date as I mentioned is wrongly typed. The other sample data which same format DDMMYYYY I found as following :

Date : 31012009 written as 4f 75 25 00
Date : 30092009 written as 41 76 25 00
Date : 01122009 written as 7f 76 25 00
Date : 02012010 written as 9f 76 25 00
Date : 30012009 written as 4e 75 25 00
Date : 01012010 written as 9e 76 25 00


So, I am not understand how it got the above. Would you show the calculation to me and to be written in C?

Thank you.
Aug 21 '08 #9
newb16
687 512MB
Oh , I am forgot that the first date as I mentioned is wrongly typed. The other sample data which same format DDMMYYYY I found as following :

Date : 31012009 written as 4f 75 25 00
Date : 30092009 written as 41 76 25 00
Date : 01122009 written as 7f 76 25 00
Date : 02012010 written as 9f 76 25 00
Date : 30012009 written as 4e 75 25 00
Date : 01012010 written as 9e 76 25 00


So, I am not understand how it got the above. Would you show the calculation to me and to be written in C?

Thank you.
Do you know how integer numbers are represented in computer?
Open windows calculatorm switch to hex. Enter 25769e( the last number, higher byte is the rightmost), press minus, enter 25754e, press '=', switch to decimal. You get 336, it is exactly a year minus one month, as the second is Dec 1 and the first is Dec 30. So the whole number looks like number of days since some date. If it were bit fields, it probably would have same bits equal if same year/month is equal, that is not this case ( 75-76 transition occurs within the same year ).
To convert it to day, monh and year, you need to find point zero, count leap years correctly (or at least as correct as the program created this format do ) find year, and convert remainder to month and day. I'm not going to do it because *) I have no original program to verify, *)it probably takes more than an hour and *)It is in no way challenging, rewarding or increasing my skills - rather boring and useless, let alone violating Teh Rulz.
Aug 21 '08 #10
Banfa
9,065 Expert Mod 8TB
By that argument you do realise that sets the epoch back in 47 centurary BC?
Aug 21 '08 #11
newb16
687 512MB
By that argument you do realise that sets the epoch back in 47 centurary BC?
If none of the higher bits actually represent some flags, there is no other guesses - at least it is correct on dates from 2008 to 2010 and no other dates are provided for us.... "When I save yellow square it is 0x12345, when I save green circle it is 0x54321, what should I do to save it as red triangle and convert it to binary? plz send codez in cpp"
Aug 22 '08 #12
Banfa
9,065 Expert Mod 8TB
If none of the higher bits actually represent some flags, there is no other guesses
Actually that is a good point, the 25 00 could be completely unrelated to the date in which case the figures give an epoch sometime in the middle of 1926, hmmmm still not conclusive though.

Definitely a case of more data required.
Aug 22 '08 #13
Actually that is a good point, the 25 00 could be completely unrelated to the date in which case the figures give an epoch sometime in the middle of 1926, hmmmm still not conclusive though.

Definitely a case of more data required.
I am not sure why end of byte is 25 00. I am still in dark to get the correct logic to get the right answer. The previous clue given, still not correct.
Aug 23 '08 #14
newb16
687 512MB
I am not sure why end of byte is 25 00. I am still in dark to get the correct logic to get the right answer. The previous clue given, still not correct.
It is not 'end of byte', it is higher 16 bits of 32 bit integer. If you state 'still not correct' please provide data that ocontradict this suggestion so that we ( may ) rectify it.
Aug 23 '08 #15
Banfa
9,065 Expert Mod 8TB
It is not 'end of byte', it is higher 16 bits of 32 bit integer.
My point is that you don't necessarily know that.

You could be looking at data that represents 2 16 bit integers, a 16 bit integer and 2 bytes, a 16 bit integer and the first 2 bytes of a 32 bit integer.

Since the OP does not appear to know the actual format of the binary data, does not appear to have given us a whole record and has not even told us what the record represents any suggestion of what the data types may be is speculation at best.

That the 4 bytes make up a 32 bit integer of number of days since a given data is possible but the given data is not enough to show it. We probably need some other examples from different years. 1 example of the data for a year in the 1800s would probably be quite edifying.
Aug 23 '08 #16
donbock
2,426 Expert 2GB
It would also be helpful to see two examples that differ by exactly one day.
Aug 27 '08 #17
Banfa
9,065 Expert Mod 8TB
It would also be helpful to see two examples that differ by exactly one day.
Actually that already exists in the supplied data

31012009 and 30012009

They aren't next to each other because the data is not ordered.
Aug 27 '08 #18
if anyone still wonders:
numbers could actually be days, as proven in earlier replies. also you have noticed two times dates that have only 1 day difference have difference of 1 in numbers. Now recalculating back to past ZERO date would be somewhere ~ {09/02/4714 BC}. I say near cause actually there are points in time where our nice dates were shifted (or entire years missing).

Now knowing that computer dates can't calculate so far in past. I've decided to cut of higher 16bits (0x0025) from actual numbers. This gave me ZERO DATE to be 12. nov 1926.

so code would be something like this:

Expand|Select|Wrap|Line Numbers
  1.  using namespace boost::gregorian;
  2.  int DaysFromZeroDate = InNumber & 0x0000FFFF; // days from 12/11/1926
  3.  date ResultDate(1926,11,12); // Zero date
  4.  ResultDate += days(DaysFromZeroDate);
  5.  
for debug purpose I would still check high 16bits (0x0025) against all dates I encounter, if there are some other numbers in higher 16bits something like:
assert(((InNumber & 0xffff0000) - 0x00250000) == 0);

If you wonder where I have took code for boost :

http://stackoverflow.com/questions/1...date-in-c-or-c

on linked page there are also other solutions how to calc difference in days that gives date as result.
Nov 1 '15 #19

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Newbie | last post by:
How would I modify this form to encode *all* the characters in the 'source' textarea to the '%xx' format & place result code into the 'output' textarea? (cross browser compatable) Any help is...
1
by: Damir Hakimov | last post by:
Hi *! I found a strange bug in base64.encode and decode, when I try to encode - decode a file 1728512 bytes lenth. Is somebody meet with this? I don't attach the file because it big, but can...
1
by: AR | last post by:
I would like to know more about the Encode/Decode feature available within MS Access. This is what I have read from Microsoft Office OnLine: "The simplest method of protection is to encode the...
2
by: student | last post by:
Hi all, Can any one help me in finding the solution to convert binary format file (ex: jpeg, bmp) to base64 using vc++ code. any help in this regard would be appreciated. thanks
7
by: jtfaulk | last post by:
I need to encode some information on the server side using ASP.NET with C#; sending via HTTP to a client side application, that needs to be decoded in an MFC C++ application. I'm not sure if I...
9
by: flanagak | last post by:
All, I was wondering if someone could point me in the right direction to decode the following information. I am working on a tool writen in C and one of the items in the file I am decoding is a...
6
by: 7stud | last post by:
s1 = "hello" s2 = s1.encode("utf-8") s1 = "an accented 'e': \xc3\xa9" s2 = s1.encode("utf-8") The last line produces the error: --- Traceback (most recent call last):
4
by: J Peyret | last post by:
Well, as usual I am confused by unicode encoding errors. I have a string with problematic characters in it which I'd like to put into a postgresql table. That results in a postgresql error so I...
1
by: anonymous | last post by:
1 Objective to write little programs to help me learn German. See code after numbered comments. //Thanks in advance for any direction or suggestions. tk 2 Want keyboard answer input, for...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.