473,396 Members | 1,757 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.

HOWTO: Calculating and Summing HEX values

Hi Gurus,
I have a date and I need to convert it into a HEX value with a checksum.

SCENARIO
===================
Starting point:
DateTime aDate = new DateTime(2003,05,29)

Expected Result:
07D3051DFC

Where the values represent:
07D3 the year
05 the month
1D the day
FC the sum of the above values (yyyy should be summed separating the first two bytes
from the second two bytes)
....like this ==> (yy + yy + mm + dd)

Can any C# guru provide me with a simple function that can take a date and create the expected HEX?

Many thanks in advanced,
Filippo.

Nov 15 '05 #1
2 18518
:)

=============================
private string CreateNewAuthorization()
{
string aStr;

string aYear1;
string aYear2;
string aMonth;
string aDay;
long aChkSum = 0;

DateTime aDate = new DateTime(2003,05,29);

aYear1 = aDate.Year.ToString("X").PadLeft(4,'0').Substring( 0,2);
aYear2 = aDate.Year.ToString("X").PadLeft(4,'0').Substring( 2,2);
aMonth = aDate.Month.ToString("X").PadLeft(2,'0');
aDay = aDate.Day.ToString("X").PadLeft(2,'0');

aStr = aYear1 + aYear2 + aMonth + aDay;
try
{
aChkSum = Convert.ToInt32(("0x" + aYear1), 16);
aChkSum = aChkSum + Convert.ToInt32(("0x" + aYear2), 16);
aChkSum = aChkSum + Convert.ToInt32(("0x" + aMonth), 16);
aChkSum = aChkSum + Convert.ToInt32(("0x" + aDay), 16);
}
catch (Exception ex)
{
return ex.Message;
}

// add the checksum of --> add HEX pairs (split year)
aStr = aStr + aChkSum.ToString("X");

return aStr;
}


"Filippo" <pa********@hotmail.com> wrote in message news:e2**************@TK2MSFTNGP12.phx.gbl...
Hi Gurus,
I have a date and I need to convert it into a HEX value with a checksum.

SCENARIO
===================
Starting point:
DateTime aDate = new DateTime(2003,05,29)

Expected Result:
07D3051DFC

Where the values represent:
07D3 the year
05 the month
1D the day
FC the sum of the above values (yyyy should be summed separating the first two bytes
from the second two bytes)
....like this ==> (yy + yy + mm + dd)

Can any C# guru provide me with a simple function that can take a date and create the expected HEX?

Many thanks in advanced,
Filippo.

Nov 15 '05 #2
:)

=============================
private string CreateNewAuthorization()
{
string aStr;

string aYear1;
string aYear2;
string aMonth;
string aDay;
long aChkSum = 0;

DateTime aDate = new DateTime(2003,05,29);

aYear1 = aDate.Year.ToString("X").PadLeft(4,'0').Substring( 0,2);
aYear2 = aDate.Year.ToString("X").PadLeft(4,'0').Substring( 2,2);
aMonth = aDate.Month.ToString("X").PadLeft(2,'0');
aDay = aDate.Day.ToString("X").PadLeft(2,'0');

aStr = aYear1 + aYear2 + aMonth + aDay;
try
{
aChkSum = Convert.ToInt32(("0x" + aYear1), 16);
aChkSum = aChkSum + Convert.ToInt32(("0x" + aYear2), 16);
aChkSum = aChkSum + Convert.ToInt32(("0x" + aMonth), 16);
aChkSum = aChkSum + Convert.ToInt32(("0x" + aDay), 16);
}
catch (Exception ex)
{
return ex.Message;
}

// add the checksum of --> add HEX pairs (split year)
aStr = aStr + aChkSum.ToString("X");

return aStr;
}


"Filippo" <pa********@hotmail.com> wrote in message news:e2**************@TK2MSFTNGP12.phx.gbl...
Hi Gurus,
I have a date and I need to convert it into a HEX value with a checksum.

SCENARIO
===================
Starting point:
DateTime aDate = new DateTime(2003,05,29)

Expected Result:
07D3051DFC

Where the values represent:
07D3 the year
05 the month
1D the day
FC the sum of the above values (yyyy should be summed separating the first two bytes
from the second two bytes)
....like this ==> (yy + yy + mm + dd)

Can any C# guru provide me with a simple function that can take a date and create the expected HEX?

Many thanks in advanced,
Filippo.

Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: PeterHardy | last post by:
I'm trying to work out an average field on a report that i'm writing and having the problem described below. e.g. if you had 3 weeks of cash which were 0, 2, 4 then a normal average would be...
0
by: Amit | last post by:
Hi: I'm trying to manually compute the ISIZE in REORGCHK for indexes in DB2 v8 (fp 4). Based on the documentation in Administrative Guide for v8, for non lob fields ISIZE should be the...
3
by: Paul Mendez | last post by:
Performance_Date SumOfBudget_NOI CurrYTD_BudgetNOI_Total 1/1/2004 $4,184,626.00 ? 2/1/2004 $4,484,710.00 ? 3/1/2004 $4,537,424.00 ? 4/1/2004 ...
0
by: Filippo | last post by:
Hi Gurus, I have a date and I need to convert it into a HEX value with a checksum. SCENARIO =================== Starting point: DateTime aDate = new DateTime(2003,05,29) Expected Result:...
0
by: hlam | last post by:
Help - Calculating the total of a column in a data grid -- when data grid is part of Master-Detail set-up I have setup a Master-Detail form using Visual Studio.Net. A ListBox is the (Master)...
2
by: MrL8Knight | last post by:
I am building a simple shopping cart and I am having problems trying to add the costs of the items to generate a total cost. I am new at this so forgive me if my technical verbiage isn’t the...
12
by: neeraj | last post by:
Hi Can any body give me the syntax for summing the elements of the an array , without looping thanks
3
by: OllyJ | last post by:
Hi guys hope you can help I have a text box for each day of the week in a form and numbers are entered into them (but sometimes they need to be left blank i.e. not 0). I am summing these values...
5
FishVal
by: FishVal | last post by:
IMHO, the following is not a how-to-do instruction to solve a particular problem but more a concept-proof stuff demonstrating possibilities of SQL. So, let us say the problem is to calculate...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.