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
2
votes
3 answers

Why does the shortcut used by BitConverter when the start index is divisible by the size of the type being converted to work?

I've recently been looking into how BitConverter works and from reading other SO questions I've read that it takes a 'shortcut' when the start index is divisible by the size of the type being converted to where it can just cast a pointer the byte at…
mclaassen
  • 5,018
  • 4
  • 30
  • 52
2
votes
1 answer

Can BitConverter be used to reliably extract multi-byte values from an IL byte stream (as returned by MethodBody.GetILAsByteArray)?

I am working on some code that parses IL byte arrays as returned by MethodBody.GetILAsByteArray. Lets say I want to read a metadata token or a 32-bit integer constant from such an IL byte stream. At first I thought using…
2
votes
1 answer

How to get sound data sample value in c#

I need to get the sample values of sound data of a WAV file so that by using those sample values i need to get the amplitude values of that sound data in every second. Important: Is there any way to get audio data sample values using Naudio library…
azeem
  • 103
  • 2
  • 7
1
vote
2 answers

improving conversions to binary and back in C#

I'm trying to write a general purpose socket server for a game I'm working on. I know I could very well use already built servers like SmartFox and Photon, but I wan't to go through the pain of creating one myself for learning purposes. I've come…
Saad Imran.
  • 4,480
  • 2
  • 23
  • 33
1
vote
1 answer

Interesting observation with BitConverter.GetBytes() in Compact Framework

I am trying to convert a float value to byte array using BitConverter.GetBytes(...) method. I came across one interesting issue. Consider following code - float f = 0.0; byte[] bytes = BitConverter.GetBytes(f); for (int j = 0; j < bytes.Length;…
Omkar
  • 2,129
  • 8
  • 33
  • 59
1
vote
1 answer

Fastest way to get sort order byte array from signed integer

I know I can use bitconverter.GetBytes to get the bytes from an integer. However, I need an array where the contents can be compared for sort order. e.g. var plusOne = BitConverter.GetBytes(1); yields bytes: 0,0,0,1 var plusOne =…
Roger Johansson
  • 22,764
  • 18
  • 97
  • 193
1
vote
0 answers

C# Bitconverter Index[0] is wrong but everything else is correct

Csharp program which i am trying to make which fits these instructions: Work continues on the remote control car project. Bandwidth in the telemetry system is at a premium and you have been asked to implement a message protocol for communicating…
DMMAHMOOD
  • 11
  • 1
1
vote
1 answer

How to Convert int to byte array and byte array to Int again? (Edit)

I am Sending 68bytes of data using UDP Protocol. 68bytes of data consist of 4byte of int and random 64byte of byte array. uint seq starts with zero and it will increase if client send datagram to server once at a time. I used BitConverter.GetBytes…
KooEunBam
  • 17
  • 1
  • 8
1
vote
1 answer

Why this unexpected output when converting Vector3[] to Byte[] and back using BitConverter?

Pardon if I'm overlooking a quick fix here, but I've read and worked through a lot of other answers dealing with converting float[] to byte[] and back to float[], but still can't figure out why I'm getting unexpected results from the code below. I'm…
gromiczek
  • 2,970
  • 5
  • 28
  • 49
1
vote
1 answer

Does BitConverter handle little-endianness incorrectly?

I'm currently writing something in C#/.NET that involves sending unsigned 16-bit integers in a network packet. The ordering of the bytes needs to be big endian. At the bit level, my understanding of 'big endian' is that the most significant bit goes…
abagonhishead
  • 300
  • 3
  • 6
1
vote
2 answers

c++ Convert string to bytes to send over tcp

I'm trying to send a 28 character string to a remote ip address and port. I've done this successfully in vb.net using the following code snippets: Dim swon As String = "A55A6B0550000000FFFBDE0030C8" Dim sendBytes As [Byte]() sendBytes =…
Chris
  • 141
  • 1
  • 1
  • 8
1
vote
2 answers

How to access individual items in serialized array?

I want to store an array of timestamps in a binary flat file. One of my requirements is that I can access individual timestamps later on for efficient query purposes without having to read and deserialize the entire array first (I use a binary…
Matt
  • 7,004
  • 11
  • 71
  • 117
1
vote
1 answer

How to convert a base64 string of bytes to Float32 or Float64?

I'm trying to convert VTK (vtu) XML-format files from base64 binary strings to ASCII strings. The files look a bit like this:
user430481
  • 315
  • 1
  • 4
  • 14
1
vote
1 answer

C# BIG Endian Format for long value

I am trying to do the following regarding my specification: The sales counter with the number of bytes N is starting with byte 0 in the BIG ENDIAN format stored as a two's complement representation ("signed"). N corresponds the number of bytes…
1
vote
3 answers

What is the endianess of a double on Windows 10 64bit?

I am using c# and writing a program to send numbers over UDP. I am on the Windows 10 64bit platform and I am using BitConverter in order to get the bytes from integers, doubles, etc.. As an example: If I use: Byte[] data =…
Spiradev
  • 13
  • 3