473,545 Members | 1,956 Online
Bytes | Software Development & Data Engineering Community
+ 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.Con vert.ToUInt32(" &H10000000") ;
int iHex2 = (int)System.Con vert.ToUInt32(" &H100000");
..
..
..
iXORValue = iNumber ^ iKey;
iCheckSumTemp = iXORValue / iHex1;
iCheckSum = iCheckSumTemp % iHex1;
..
..
..
return iXORValue.ToStr ing() + "-" + iCheckSum.ToStr ing();

Thanks for any help
Andy
Nov 16 '05 #1
3 7867
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.Con vert.ToUInt32(" &H10000000") ;
int iHex2 = (int)System.Con vert.ToUInt32(" &H100000");
Here's the error! Instead you should have:

int iHex1 = (int)System.Con vert.ToUInt32(" 0xH10000000",16 );
int iHex2 = (int)System.Con vert.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.ToStr ing() + "-" + iCheckSum.ToStr ing();

Thanks for any help
Andy

Nov 16 '05 #2
int iHex1 = (int)System.Con vert.ToUInt32(" 0xH10000000",16 );
int iHex2 = (int)System.Con vert.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.Con vert.ToUInt32(" &H10000000") ;
int iHex2 = (int)System.Con vert.ToUInt32(" &H100000");
.
.
.
iXORValue = iNumber ^ iKey;
iCheckSumTemp = iXORValue / iHex1;
iCheckSum = iCheckSumTemp % iHex1;
.
.
.
return iXORValue.ToStr ing() + "-" + iCheckSum.ToStr ing();

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
5108
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 accepts messages from .NET clients. The web method call includes an object as one of it's parameters - this reflected object has been given a...
8
3789
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 got to write them in a bmp file (in which RGB values are limited to 8 bits per channel). so i need to have them scaled down. first of all i find...
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 that uses numerous large db applications (including Oracle, JD Edwards, & an archaic mainframe) for financial and contractual record keeping...
31
6582
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 variable becomes 364 and the other one becomes 365. Does anyone have any insight to what the problem is? Thanks in advance. Bjørn
4
6473
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? Thanks in advance... -Nikhil
7
1692
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
4444
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 value. This will be entered into tblTests. There are 4 data fields in tblSamples (Data1, Data2, Data3, Data4). When setting up a new test the user...
24
2331
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
1687
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? Thanks, Shelley
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 calculations. A sample of the input is : 00000000000020E0000032F800000000400022005E The problem I am facing is this: I am using f.read(2) to read a...
0
7484
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7415
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7675
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7928
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
5344
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3470
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3451
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1030
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
726
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.