Click here to Skip to main content
11,797,355 members (79,423 online)
Rate this: bad
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
Edited 27-Dec-12 3:07am
ProgramFOX at 27-Dec-12 8:09am
What's the error?
hemantrautela at 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.

Smile | :)
hemantrautela at 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 at 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 at 27-Dec-12 12:56pm
somefunction() returns a byte array, it is implementd for RSA algorithm
Oleksandr Kulchytskyi at 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
0 CPallini 475
1 Maciej Los 370
2 OriginalGriff 363
3 Abhinav S 344
4 Andy Lanng 296
0 OriginalGriff 2,092
1 Maciej Los 1,760
2 KrunalRohit 1,436
3 CPallini 1,245
4 ppolymorphe 893

Advertise | Privacy | Mobile
Web02 | 2.8.151002.1 | Last Updated 27 Dec 2012
Copyright © CodeProject, 1999-2015
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