Click here to Skip to main content
Rate this: bad
good
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 3:06am
Edited 27-Dec-12 4:07am
v5
Comments
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
good
Please Sign up or sign in to vote.

Solution 2

Hi,
 
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 | :)
  Permalink  
Comments
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
good
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
  Permalink  
Comments
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 Sergey Alexandrovich Kryukov 275
1 OriginalGriff 230
2 BillWoodruff 173
3 CPallini 155
4 Kamal Rocks 144
0 OriginalGriff 5,655
1 DamithSL 4,506
2 Maciej Los 3,997
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,180


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