Questions tagged [bitconverter]

Class in C# and Java that converts base data types to an array of bytes, and an array of bytes to base data types.

Class in C# and Java that converts base data types to an array of bytes, and an array of bytes to base data types.

138 questions
1
vote
1 answer

sprintf not giving expected values

I have an array (readingreg[4]) that gets filled with hex digits. My goal is to convert the datatype into a string. I have read some suggestions and it seems that sprintf is the way to go. This is what I tried: sprintf(server0, "0x%02X",…
KS7X
  • 332
  • 2
  • 15
1
vote
1 answer

Why I can't convert a byte[2] array to int with BitConverter?

The main problem is that I recive a binary number with only 10 bits in use from a SerialPort so I use this to receive the complete data: byte[] buf = new byte[2]; serialPort.Read(buf, 0, buf.Length); BitArray bits = new BitArray(buf); The original…
1
vote
1 answer

Slow Processing

Well, I'm trying to convert various data "bytes" to "long". And it seems to be very slow ... Code: For X = 0 To Map.MaxX For Y = 0 To Map.MaxY Map.Tile(X, Y).Data1 = Buffer.ReadLong Map.Tile(X, Y).Data2 =…
user3571412
  • 105
  • 1
  • 9
1
vote
1 answer

Issues with Generics using Silverlight

I am creating a C# web application using Silverlight 5 (VS 2010). I initially created a console application which works fine and now i am adapting it into a web app. Even in web application it is working fine for particularly set data type (say…
Sss
  • 1,519
  • 8
  • 37
  • 67
1
vote
2 answers

Why is BitConverter slower than doing the bitwise operations directly?

I recently did some profiling on some code and found that the largest CPU usage was being consumed by calls to BitConverter such as: return BitConverter.ToInt16(new byte[] { byte1, byte2 }); when switching to something like: return (short)(byte1 <<…
mclaassen
  • 5,018
  • 4
  • 30
  • 52
1
vote
0 answers

Azure switching from little endian to big endian when deployed

Okay, I have this weird issue. I've created a workerrole which connects to a chatserver using TcpClient and Reactive Extensions. The code works when I run in the emulator. In the beginning I thought there was some issues with Rx, but what it looks…
EMB
  • 171
  • 1
  • 7
1
vote
2 answers

c# bitconverter.ToString convert to hexadecimal string

I am using BitConverter.ToString(bytes) for converting by string to hexadecimal string which I further convert it into integer or float. But the input stream consist of 0 to show that byte value is 0. So suppose I have an integer which is…
prattom
  • 1,625
  • 11
  • 42
  • 67
1
vote
0 answers

VB.net TCP Streaming bytes, Arithmetic Operation Resulted In An Overflow

I have been working on this for a few days now and I'm just spinning my wheels. This is a piece of vb.net code that is for connecting to an api of mikrotik routers. It was provided on their wiki but there is an error that pops up and I'm having a…
MrUsogi
  • 11
  • 1
1
vote
1 answer

Converting `UInt16` to byte array

How to convert an UInt16 valu to a byte array of size 2 I found some code in MSDN but I am not sure if it is ok to use in my case: // Convert a ushort argument to a byte array and display it. public static void GetBytesUInt16( ushort argument ) { …
Dumbo
  • 13,555
  • 54
  • 184
  • 288
1
vote
0 answers

Wondering how best to extend logic for checking if IPv4 address is in a given range to IPv6?

I currently have this method derived from a couple of other S.O. posts: public bool IsIPAddressInRange(IPAddress ipAddress) { int startIntAddress = BitConverter.ToInt32(StartingIPAddress.GetAddressBytes(), 0); int endIntAddress =…
Sean Anderson
  • 27,963
  • 30
  • 126
  • 237
0
votes
1 answer

How does BitConverter.ToInt64 handles a byte arry with 32 bytes (a 256 bit hash from SHA256Managed)

I'm using SHA256Managed to generate 256 bit hashs and I would like to store them on sql server. How good is BitConverter.ToInt64 for this? Does it ignore the extra bytes? Should I do some processing to reduce the byte array before converting to…
Manuel Alves
  • 3,885
  • 2
  • 30
  • 24
0
votes
2 answers

Reading MP3 Frameheader - assigning bit values to variables

I am learning visual basic .net and I am attempting to translate some java source code to a vb.net project. The project reads mp3 details and then splits the file accurately according to the frameheader details etc. My question relates to reading…
mheptinstall
  • 2,109
  • 3
  • 24
  • 44
0
votes
3 answers

Convert eight bytes into a string

i have eight byte variables: Byte7 = 0 dez, hex: 00 Byte6 = 2 dez, hex: 02 Byte5 = 32 dez, hex: 20 Byte4 = 33 dez, hex: 21 Byte3 = 17 dez, hex: 11 Byte2 = 37 dez, hex: 25 Byte1 = 3 dez, hex: 03 Byte0 = 88 dez, hex: 58 Question: How can i put all…
Markus.H1
  • 31
  • 7
0
votes
0 answers

C# BitConverter byte array to ushort (int16, double, boolean, single, int32, ) to use in Unreal

(Sending 'data' over TCP) byte[] data = {153, 130, 0, 0 }; index = 0; ushort nm = ExtractUshort(); public ushort ExtractUshort() { ushort value = BitConverter.ToUInt16(data, index); index += 2; …
0
votes
1 answer

How to convert float value to byte in c#

I want to convert 794.328247 value to byte. I used Convert.ToByte(794.328247) but it showing following error, Error : - Value was either too large or too small for an unsigned byte. So anyone can help me to resolve this issue. Thanks.