base256

  • Thread starter Thread starter William Stacey [MVP]
  • Start date Start date
Base 256... wouldn't that be a byte stream? :)

BinaryWriter's Write(long) on a MemoryStream would do it wouldn't it?
 
Maybe it is John and I am reading more into it. I was doing something with
rfc2945:
"An n-byte string S can be converted to an integer as follows:

i = S[n-1] + 256 * S[n-2] + 256^2 * S[n-3] + ... + 256^(n-1) * S[0]

where i is the integer and S[x] is the value of the x'th byte of S.
In human terms, the string of bytes is the integer expressed in base
256, with the most significant digit first. When converting back to
a string, S[0] must be non-zero (padding is considered to be a
separate, independent process). This conversion method is suitable
for file storage, in-memory representation, and network transmission
of large integer values. Unless otherwise specified, this mapping
will be assumed."

Maybe just xxx.GetBytes() is all I need?

--
William Stacey, MVP
http://mvp.support.microsoft.com

John Wood said:
Base 256... wouldn't that be a byte stream? :)

BinaryWriter's Write(long) on a MemoryStream would do it wouldn't it?
 
William Stacey said:
Maybe it is John and I am reading more into it. I was doing something with
rfc2945:
"An n-byte string S can be converted to an integer as follows:

i = S[n-1] + 256 * S[n-2] + 256^2 * S[n-3] + ... + 256^(n-1) * S[0]

where i is the integer and S[x] is the value of the x'th byte of S.
In human terms, the string of bytes is the integer expressed in base
256, with the most significant digit first. When converting back to
a string, S[0] must be non-zero (padding is considered to be a
separate, independent process). This conversion method is suitable
for file storage, in-memory representation, and network transmission
of large integer values. Unless otherwise specified, this mapping
will be assumed."

Maybe just xxx.GetBytes() is all I need?

That looks like the wrong endianness for BitConverter, but you could
use my EndianBitConverter in MiscUtil:
http://www.pobox.com/~skeet/csharp/miscutil

Of course, it'll only work where n <= 8...
 
Jon,
A binaryWriter with a configurable endian is actually extremely useful for
me, thanks for that.

--
John Wood
Blog: http://spaces.msn.com/members/johnwood


Jon Skeet said:
William Stacey said:
Maybe it is John and I am reading more into it. I was doing something
with
rfc2945:
"An n-byte string S can be converted to an integer as follows:

i = S[n-1] + 256 * S[n-2] + 256^2 * S[n-3] + ... + 256^(n-1) * S[0]

where i is the integer and S[x] is the value of the x'th byte of S.
In human terms, the string of bytes is the integer expressed in base
256, with the most significant digit first. When converting back to
a string, S[0] must be non-zero (padding is considered to be a
separate, independent process). This conversion method is suitable
for file storage, in-memory representation, and network transmission
of large integer values. Unless otherwise specified, this mapping
will be assumed."

Maybe just xxx.GetBytes() is all I need?

That looks like the wrong endianness for BitConverter, but you could
use my EndianBitConverter in MiscUtil:
http://www.pobox.com/~skeet/csharp/miscutil

Of course, it'll only work where n <= 8...
 
Back
Top