473,480 Members | 1,506 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 7860
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
5081
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
3779
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
322
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
6572
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
6463
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
1687
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
4436
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
2323
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
1674
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
3191
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
7044
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
7045
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
7087
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...
1
6741
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
5341
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,...
1
4782
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4483
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2995
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
182
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.