Valwex
Valwex
CC#
Created by Valwex on 7/28/2023 in #help
❔ Read bits from a byte[] array
Hi, I was looking for a way to read bits in a byte[] array and advance the position, and I came across the BitStream library (https://github.com/Sewer56/Sewer56.BitStream) because we can't do it natively in C#. The problem is that I've noticed that I'm not getting the expected behavior in my code At first, I need to read an int32 in my byte stream, so I did :
var stream = new ArrayByteStream(buffer);
var bitStream = new BitStream<ArrayByteStream>(stream);
var header = bitStream.Read<int>();
Console.WriteLine(header);
var stream = new ArrayByteStream(buffer);
var bitStream = new BitStream<ArrayByteStream>(stream);
var header = bitStream.Read<int>();
Console.WriteLine(header);
And in output I get :
671088640
687865856
704643072
721420288
738197504
754974720
771751936
788529152
805306368
822083584
838860800
671088640
687865856
704643072
721420288
738197504
754974720
771751936
788529152
805306368
822083584
838860800
Normally I'd get something shorter like this:
67
68
69
70
71
72
73
74
75
76
77
78
67
68
69
70
71
72
73
74
75
76
77
78
I don't want to write a code that will only retrieve the first two characters because I don't necessarily know the size Do you know why the BitStream library reacts like this? When I use MemoryStream + BinaryReader it works perfectly except that I get stuck when I have to read bits in a stream... Thanks a lot 🙏
55 replies
CC#
Created by Valwex on 7/18/2023 in #help
❔ Initializing an object
Hello, what is the difference between these two lines?
var p = new Point() { X = 42, Y = 13 };
var p = new Point() { X = 42, Y = 13 };
and
var p = new Point(42, 13);
var p = new Point(42, 13);
I know that the first allows you to initiate an object, but I don't understand the difference
36 replies