Click here to Skip to main content
15,892,809 members
Please Sign up or sign in to vote.
1.00/5 (4 votes)
See more:
Hi
Can any body tell me how this Convert.ToChar() method giving following result.



VB
Convert.ToChar('a'|'b'|'c')
 output 99 'c'
Convert.ToChar('a'|'b'|'d')
output 103 'g'



Thanks
Posted
Comments
Sergey Alexandrovich Kryukov 21-Mar-13 0:39am    
Are you serious? What's the problem here?
—SA
Kuthuparakkal 21-Mar-13 0:52am    
You can learn Operator (|) from msdn....
Code_seeker_ 21-Mar-13 0:56am    
tx for your comments ,I know how these boolean operators will work..I am asking how this will work on above scenario..
do't show over smartness...

The symbol '|' refers to [EDIT]Boolean Integer bitwise "OR" (it is Boolean "OR" only if both operands are
bool)[/EDIT] operator...<br />
<br />
ASCII values for 'a' is 97, 'b' is 98, 'c' is 99 ....<br />
<br />
binary values for 97 is 01100001, 98 is 01100010, 99 is 01100011 ......<br />
<br />
Ex 1: 97 - 01100001 = a <br />
      98 - 01100010 = b<br />
-----------------------------<br />
      99 - 01100011 = c<br />
      99 - 01100011 = c<br />
------------------------------<br />
      99 - 01100011 = c = final answer<br />
<br />
Ex 2: 97 - 01100001 = a <br />
      98 - 01100010 = b<br />
-----------------------------<br />
      99 - 01100011 = c<br />
     100 - 01100100 = d<br />
------------------------------<br />
     103 - 01100111 = g - final answer<br />
<br />
refer below links for more info..<br />
<a href="http://numerical19.tripod.com/binary_code.htm">http://numerical19.tripod.com/binary_code.htm</a>[<a href="http://numerical19.tripod.com/binary_code.htm" target="_blank" title="New Window">^</a>]<br />
<a href="http://www.asciitable.com/">http://www.asciitable.com/</a>[<a href="http://www.asciitable.com/" target="_blank" title="New Window">^</a>]
 
Share this answer
 
v4
Comments
Code_seeker_ 21-Mar-13 2:00am    
Got.... thanq very much....great explanation....
Code_seeker_ 21-Mar-13 3:02am    
ya sure..
Joezer BH 21-Mar-13 3:53am    
Nice work!
5+
vinodkumarnie 21-Mar-13 4:33am    
Thank you very much..
Sergey Alexandrovich Kryukov 21-Mar-13 18:09pm    
My 5. Less lazy than mine... :-)
Interesting that even the vote of 1 presents. I believe that if you have many votes, the picture would clearly demonstrate the Pareto distribution. I hope you know what is it: 80% of population carry 20% of knowledge, there rest 20% — the rest 80%. Or 95% vs. 5%, if not worse... :-)
—SA
No need to waste words on it. This is how it should be. What, never saw the operation of bitwise OR ('|') operator? Then read about it.

—SA
 
Share this answer
 
v2
Comments
Code_seeker_ 21-Mar-13 1:00am    
is it ? I know OR operator, I don't know really how its working on above scenario .. Tell me how it works... if you are really that much smart as your talking...
Sergey Alexandrovich Kryukov 21-Mar-13 1:03am    
Yes. I hope you don't need to get multiplication table explained. This is the same thing. 1 | 1 = 1 | 0 = 0 | 1 = 1, 0 | 0 = 0.
—SA
Code_seeker_ 21-Mar-13 1:08am    
good joke buddy,don't explain me.. about or operator I already told you that I know.. Just explain about how it works on above scenario..
Sergey Alexandrovich Kryukov 21-Mar-13 1:12am    
I did not try to joke with you. There is no a scenario. As soon as you read about |, you will see it. What Convert does? It acts line (char)intValue. Those characters are ORed as 16-bit integers (Unicode UTF-16LE values of their code point) casted to char.
What else?
—SA
Code_seeker_ 21-Mar-13 2:11am    
-SA see above explanation...its very nice..
The | operator stands for a boolean OR.
In your code, the integer values for a, b and c are being converted to their equivalent booleann values and then 'ORed' together and thus you get the final value which is c or g.
 
Share this answer
 
v2
Comments
Code_seeker_ 21-Mar-13 0:58am    
tx abhinav..but I have little bit confusion on above scenario..
Sergey Alexandrovich Kryukov 21-Mar-13 1:12am    
Sure, a 5. OP asks for more explanations; I have no idea what else to explain...
—SA
Abhinav S 21-Mar-13 1:50am    
Thank you SA.
Joezer BH 21-Mar-13 3:54am    
ORred => ORed
Abhinav S 21-Mar-13 23:14pm    
Thanks :).

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900