Getting byte[] representation of .NET primitive types

  • Thread starter Thread starter Smugsboy
  • Start date Start date
S

Smugsboy

Hi,
Is there a way to get byte[] representation of primitive types ?
Meaning:

for "ushort val = 6"
to get the following "byte[2] { 0, 6 }"
and for "byte val = 6"
to get the following "byte[1] { 6 }"

Thanks,
 
Hi Smugsboy,
Is there a way to get byte[] representation of primitive types ?
Meaning:

for "ushort val = 6"
to get the following "byte[2] { 0, 6 }"
and for "byte val = 6"
to get the following "byte[1] { 6 }"

See: BitConverter
http://msdn.microsoft.com/library/en-
us/cpref/html/frlrfsystembitconvertermemberstopic.asp

Especially: BitConverter.GetBytes:
http://msdn.microsoft.com/library/en-
us/cpref/html/frlrfsystembitconverterclassgetbytestopic.asp
--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/
 
Did the trick for me. Thanks.

Jochen said:
Hi Smugsboy,
Is there a way to get byte[] representation of primitive types ?
Meaning:

for "ushort val = 6"
to get the following "byte[2] { 0, 6 }"
and for "byte val = 6"
to get the following "byte[1] { 6 }"

See: BitConverter
http://msdn.microsoft.com/library/en-
us/cpref/html/frlrfsystembitconvertermemberstopic.asp

Especially: BitConverter.GetBytes:
http://msdn.microsoft.com/library/en-
us/cpref/html/frlrfsystembitconverterclassgetbytestopic.asp
--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/
 
Back
Top