Click here to Skip to main content
13,148,224 members (47,797 online)
Rate this:
Please Sign up or sign in to vote.
I have below code
byte[] bytestring= somefunction(); 
//somefunction() return a byte array..
 string st1 =  Encoding.UTF32.GetString(bytestring);
 byte[] bytestring2 = Encoding.UTF32.GetBytes(st1);
 bool st =  bytestring2.Equals(bytestring);
// RESULT IS st = false  
// Desired result st = true

I getting st = false, But I think it should be true...
what is the problem in ablove code I tried UTF8 , UnicodeEncoding .but result is same.
If bytestring2 has encoded value then how decode it( how get my old value)...

Thanks in Advance
Hemant Singh[^]
Posted 27-Dec-12 2:06am
Updated 27-Dec-12 3:07am
ProgramFOX 27-Dec-12 8:09am
What's the error?
hemantrautela 27-Dec-12 9:00am
the boolean variable st value is false.
But i think it should be true....
Rate this: bad
Please Sign up or sign in to vote.

Solution 2


String.Equals don't have any overload on byte array, when you pass byte array to equals function that treated as object, so no compilation error occur but it's returns false.

hemantrautela 27-Dec-12 12:53pm
It is not String.Equals

bytestring2 and bytestring both are byte array.

It is object.Equals(object) method.
Suvabrata Roy 27-Dec-12 23:56pm
Then Check your SomeFunction(), it returning properly or not
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You must exactly know what is going on under the hood in method
byte[] bytestring= somefunction(); 

For exampple what is it converted fron a specific text encoding to byte array,
and what i have seen, you just try to convert it bytes with UTF encoding , and check thei equality
hemantrautela 27-Dec-12 12:56pm
somefunction() returns a byte array, it is implementd for RSA algorithm
Oleksandr Kulchytskyi 27-Dec-12 14:24pm
I saw that somefuc returns a bytes array , that is all what i know.
But what exact it does? which encodings , and so on??

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web02 | 2.8.170924.2 | Last Updated 27 Dec 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100