Those are two different goals: 1) serialize a general-case string; which can be done using
, and the result depends on the encoding used; if the encoding represents one of Unicode UTFs, all results will be different but equivalent, and the failure to use UTF can lead to data loss (think '????' characters); 2) serialization of a number represented by a string.
In the second case, it has nothing to do with
. You should work with data, not with the strings representing data. The strings can be used only for presentation of data in UI, human-readable files and the like.
Anyway, you can parse a string to any numeric type using their
methods. For example:
(Please see other numeric types you might need.)
And then, you can serialize numeric value to array of bytes — and back. Please see the class