M
Marc Gravell
Short version: is it possible to control the endian-ness of BitConverter? -
or are there any /framework/ methods like
BigEndianBitConverter.GetBytes(long) and .ToInt64()?
(I am not after equivalent code; I already have that)
===
Background:
I'm dealing with Sql-Server timestamp fields [which are equivalent to the
binary(8) sql data-type]; in some circumstances (e.g. OpenXml) they need to
be representated using the bigint sql-datatype (equiv. to the c# long); the
sql cast between bigint and binary(8) is (as far as I can tell) big-endian.
Now; when I get the timestamp (as a byte[]) from the database in C#, it also
appears to be big-endian; I want to convert this to a long, so that I can
use it in an xml structure for OpenXml later on (for a complex block
update); for efficiency (and simplicity) I had hoped to use BitConverter,
but this (on my environment, at least) is little-endian.
Obviously it is fairly simple to code this translation (have done it; it
works fine - this is not the problem), but is there a framework way of doing
this conversion? I realise that simple byte-shifts and binary-ORs work very
efficiently, but the code would be used a fair bit, and often the framework
wrappers can cheat and do things even more frugally... (and yes: this is
probably "premature optimisation", but the question stands...)
Or am I being too hopeful?
Marc
or are there any /framework/ methods like
BigEndianBitConverter.GetBytes(long) and .ToInt64()?
(I am not after equivalent code; I already have that)
===
Background:
I'm dealing with Sql-Server timestamp fields [which are equivalent to the
binary(8) sql data-type]; in some circumstances (e.g. OpenXml) they need to
be representated using the bigint sql-datatype (equiv. to the c# long); the
sql cast between bigint and binary(8) is (as far as I can tell) big-endian.
Now; when I get the timestamp (as a byte[]) from the database in C#, it also
appears to be big-endian; I want to convert this to a long, so that I can
use it in an xml structure for OpenXml later on (for a complex block
update); for efficiency (and simplicity) I had hoped to use BitConverter,
but this (on my environment, at least) is little-endian.
Obviously it is fairly simple to code this translation (have done it; it
works fine - this is not the problem), but is there a framework way of doing
this conversion? I realise that simple byte-shifts and binary-ORs work very
efficiently, but the code would be used a fair bit, and often the framework
wrappers can cheat and do things even more frugally... (and yes: this is
probably "premature optimisation", but the question stands...)
Or am I being too hopeful?
Marc