D
Dennis Myrén
Hi.
Is there a way to utilize the great primitive data type
formatting routines available in .NET without working with
strings?
I want a byte [] directly rather than a string.
I think it is unfortunate that i have to walk via System.String to do that.
For instance, from an integer of value 123, i want:
new byte [3] { ASCII.Digit1, ASCII.Digit2, ASCII.Digit3 }
I have managed to write my own formatting routines for
integer types ushort, short, uint, int, ulong and long
that create a byte array directly without walking via string.
But the floating point formatting routines is kind of complicated,
i rather not writing them if someone else has already done it and are
willing to share
that or (but i have never seen anything like it) if the .NET framework
provides something
for this. I am looking to be as efficient as possible
(that is why i am interested in this in the first place).
By now, i have to do a Math.Round, then format the number into string(also
passing a NumberFormatInfo),
then create a byte array from that. It is just too much overhead.
I always want the real numbers formatted with a maximum precision of 5
decimals,
using '.' for number group separator.
For instance, from a float of value 3.14F, i want:
new byte [4] { ASCII.Digit3, ASCII.Dot, ASCII.Digit1, ASCII.Digit4 };
If there is nothing like it, do you know where to find information
about the internal bit-level RAM representation of System.Single/Double?
How can i solve this?
Is there a way to utilize the great primitive data type
formatting routines available in .NET without working with
strings?
I want a byte [] directly rather than a string.
I think it is unfortunate that i have to walk via System.String to do that.
For instance, from an integer of value 123, i want:
new byte [3] { ASCII.Digit1, ASCII.Digit2, ASCII.Digit3 }
I have managed to write my own formatting routines for
integer types ushort, short, uint, int, ulong and long
that create a byte array directly without walking via string.
But the floating point formatting routines is kind of complicated,
i rather not writing them if someone else has already done it and are
willing to share
that or (but i have never seen anything like it) if the .NET framework
provides something
for this. I am looking to be as efficient as possible
(that is why i am interested in this in the first place).
By now, i have to do a Math.Round, then format the number into string(also
passing a NumberFormatInfo),
then create a byte array from that. It is just too much overhead.
I always want the real numbers formatted with a maximum precision of 5
decimals,
using '.' for number group separator.
For instance, from a float of value 3.14F, i want:
new byte [4] { ASCII.Digit3, ASCII.Dot, ASCII.Digit1, ASCII.Digit4 };
If there is nothing like it, do you know where to find information
about the internal bit-level RAM representation of System.Single/Double?
How can i solve this?