Carefull about object.ToString()[i]: the output is char type. If you Convert that value to int, you will get chars representation in int. To get the value of the char, the simple way is to convert it to string: