[Closed] Endian dotnet
Could anyone tell me how to build a function from this dotnet code into max.
namespace EndianReverser {
class Class1 {
static void Main(string[] args) {
Console.WriteLine(“0xAABBCCDD = 0x{0}”,
EndianReverse(0xAABBCCDD).ToString(“X”));
Console.WriteLine(“0xFF000000 = 0x{0}”,
EndianReverse(0xFF000000).ToString(“X”));
Console.WriteLine(“0xFF = 0x{0}”, EndianReverse(0xFF).ToString(“X”))
;
}
static uint EndianReverse(uint x) {
return ((x<<24) | ((x & 0xff00)<<8) | ((x & 0xff0000)> >8) | (x>>24))
;
}
}
}
this is what I want to accomplish using dotnet in max instead of needing a plugin also in max.
the plugin code does this function.
// – floatSwap —————————————————
//
float FloatSwap( float f )
{
union
{
float f;
unsigned char b[4];
} dat1, dat2;
dat1.f = f;
dat2.b[0] = dat1.b[3];
dat2.b[1] = dat1.b[2];
dat2.b[2] = dat1.b[1];
dat2.b[3] = dat1.b[0];
return dat2.f;
}
Value *Ext_FloatSwap_cf(Value **arg_list, int count)
{
// Check the function receives one argument
check_arg_count(Ext_FloatSwap, 1, count);
// Check the function argument is a Float type_check(arg_list[0], Float, "argument");
float intern = FloatSwap(arg_list[0]->to_float());
return new Float(FloatSwap(arg_list[0]->to_float()));
}
// —————————————————————-
so in max I can do floatswap() and it will change the endian order of that variable float
what is the reason to use dotnet? Speed? Memory saving? you can do it with MXS…
-- i prefer this one
fn floatSwap1 f =
(
d = 2^8
i = bit.floatAsInt f
b1 = i/d
b0 = (mod i d) as integer
b2 = b1/d
b1 = (mod b1 d) as integer
b3 = b2/d
b2 = (mod b2 d) as integer
swap b3 b0
swap b2 b1
i = b0 + b1*d + b2*(2^16) + b3*(2^24)
bit.intAsFloat i
)
fn floatSwap2 f =
(
i = bit.floatAsInt f
h = bit.intashex i
while h.count < 8 do h = "0" + h
s = (substring h 7 2) + (substring h 5 2) + (substring h 3 2) + (substring h 1 2)
bit.intAsFloat (bit.hexasint s)
)