473,403 Members | 2,359 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,403 software developers and data experts.

Hex Conversion and Calculations

I am trying to create an encryption routine (although VERY basic I know), but
I am getting a "input string was not in a correct format" error and not sure
what I am doing wrong. All my variables are int. iNumber is the value
passed into the function. The error is happening on the first line of the
code posted below.

int iHex1 = (int)System.Convert.ToUInt32("&H10000000");
int iHex2 = (int)System.Convert.ToUInt32("&H100000");
..
..
..
iXORValue = iNumber ^ iKey;
iCheckSumTemp = iXORValue / iHex1;
iCheckSum = iCheckSumTemp % iHex1;
..
..
..
return iXORValue.ToString() + "-" + iCheckSum.ToString();

Thanks for any help
Andy
Nov 16 '05 #1
3 7859
Andy wrote:
I am trying to create an encryption routine (although VERY basic I know), but
I am getting a "input string was not in a correct format" error and not sure
what I am doing wrong. All my variables are int. iNumber is the value
passed into the function. The error is happening on the first line of the
code posted below.

int iHex1 = (int)System.Convert.ToUInt32("&H10000000");
int iHex2 = (int)System.Convert.ToUInt32("&H100000");
Here's the error! Instead you should have:

int iHex1 = (int)System.Convert.ToUInt32("0xH10000000",16);
int iHex2 = (int)System.Convert.ToUInt32("0xH100000",16);

First, in c# you start a hex number from 0x, and second, you need to specify the number base,
which is 16.

God luck!
Andrey
.
iXORValue = iNumber ^ iKey;
iCheckSumTemp = iXORValue / iHex1;
iCheckSum = iCheckSumTemp % iHex1;
.
.
.
return iXORValue.ToString() + "-" + iCheckSum.ToString();

Thanks for any help
Andy

Nov 16 '05 #2
int iHex1 = (int)System.Convert.ToUInt32("0xH10000000",16);
int iHex2 = (int)System.Convert.ToUInt32("0xH100000",16); ^
Get rid of the H too.

First, in c# you start a hex number from 0x,


Right, but that doesn't really matter here since you're passing in a
string. So the calling language is irrelevant, what matters is that
the Convert APIs expect a 0x prefix.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 16 '05 #3
Thank you. That solved my problem

"Andy" wrote:
I am trying to create an encryption routine (although VERY basic I know), but
I am getting a "input string was not in a correct format" error and not sure
what I am doing wrong. All my variables are int. iNumber is the value
passed into the function. The error is happening on the first line of the
code posted below.

int iHex1 = (int)System.Convert.ToUInt32("&H10000000");
int iHex2 = (int)System.Convert.ToUInt32("&H100000");
.
.
.
iXORValue = iNumber ^ iKey;
iCheckSumTemp = iXORValue / iHex1;
iCheckSum = iCheckSumTemp % iHex1;
.
.
.
return iXORValue.ToString() + "-" + iCheckSum.ToString();

Thanks for any help
Andy

Nov 16 '05 #4

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

Similar topics

0
by: Symon R | last post by:
This is a bit of a weird one that I haven't yet been able to solve - I'm hoping someone out there can disprove my findings and tell me where I've gone wrong! I have designed a web service that...
8
by: CAFxX | last post by:
i'm writing a program that executes some calculations on a bitmap loaded in memory. these calculation ends up with pixel wth values far over 255, but i need them to be between 0 and 255 since i...
4
by: neptune | last post by:
I've been reading the numerous posts on using SQL Server vs. Access, but still don't know if SQL server is right for my applications. I work in a section of a large corporate accounting department...
31
by: Bjørn Augestad | last post by:
Below is a program which converts a double to an integer in two different ways, giving me two different values for the int. The basic expression is 1.0 / (1.0 * 365.0) which should be 365, but one...
4
by: Nikhil Patel | last post by:
Hi all, I am a VB6 programmer and learning C#. I am currently reading a chapter on types. I have question regarding enums. Why do we need to convert enum members to the value that they represent?...
7
by: Alphonse Giambrone | last post by:
How can I convert a string to a different type based on another string or other variable? For instance, instead of Dim i as Integer i = ctype("1000", Integer) I would like to do
5
by: DBQueen | last post by:
I have a database where the user will have the opportunity to set up a number of Tests. I want the user to be able to enter the equation if a field for a particular test is to be a calculated...
24
by: Rajesh S R | last post by:
Isn't this code violation of C99 standard? #include <stdio.h> int main( void ) { float a = 0.7; if(a < 0.7) printf("Wrong"); else
2
by: sbowman | last post by:
I've seen a lot of tools out there that automatically convert Access apps to .NET. If anyone has used one, I'd like to know which one and what you thought of it. Are they really worth the money? ...
5
by: Praveena P | last post by:
Hi folks, I am new to Python... so am not too sure about how the type conversion works. I have to read a file that contains hexadecimal data and use the data further to do some arithmetic...
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: 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:
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...
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.