IrApp
IrApp

Reputation: 1843

WPF Convert hex to UInt

I want to convert Hexadecimal into a UInt. The problem is the following:

when I try this:

uint value = Convert.ToUInt32((hex), 16);

and the hex is for example 12 bytes size, all works fine, but when I try to convert a hex with 32 bytes size I have this error:

value too large or too small for int32

Then I try this :

ulong = Convert.ToUInt64((hex), 16);

and I get this error.

value too large or too small for int64

Someone Knows what I am doing wrong?

Upvotes: 1

Views: 416

Answers (2)

IrApp
IrApp

Reputation: 1843

Finally I cut the hexadecimal number like this:

Hex = 1234567891123456789223456789

ulong result= Convert.ToUInt64(12345678911234, 16);
result += Convert.ToUInt64(56789223456789, 16);

That resolve my problem. Thanks for the replies, made me think!!!

Upvotes: 0

roxik0
roxik0

Reputation: 97

Sowi error is correct: https://msdn.microsoft.com/pl-pl/library/system.uint64.maxvalue(v=vs.110).aspx 0xFFFFFFFFFFFFFFFF is max Uint64 value. You tried to input: 0x1234567891123456789223456789 what is much bigger value.

Upvotes: 0

Related Questions