0

(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;
            return value;
        }

    Debug.Log("nm value >" + nm); 

Log output gives "nm value > 33433" in Unity.

I want to understand how this works and use it in unreal (c++ or blueprint).

Some other types:
    - double value = BitConverter.ToDouble(data, index);     (index += 8)
    - bool value = BitConverter.ToBoolean(data, index);     (index += 1)
    - float value = BitConverter.ToSingle(data, index);     (index += 4)
    - uint value = BitConverter.ToUInt32(data, index);     (index += 4)
    - int value = BitConverter.ToInt32(data, index);     (index += 4)
  • 1
    So your question is how to write something like BitConverter in C++? – john Jun 12 '22 at 21:13
  • Just tried; https://www.rapidtables.com/convert/number/decimal-to-hex.html 153 -> 99 /// 130 -> 82 after: https://www.scadacore.com/tools/programming-calculators/online-hex-converter/ 99 82 (hex string input) gives 33433 on right bottom. (UINT16 - Little Endian (BA)) – draper.kaegan Jun 12 '22 at 21:14
  • @john of course maybe something like that, its not problem on unity (bcus of bitconverter on c# i think), just tryn to make my project on unreal and stuck on there. is there any plugin for unreal or bluprint way in unreal ? – draper.kaegan Jun 12 '22 at 21:16
  • You’re probably looking for reinterpret_cast. That being said, imo the best way to handle network data is probably going to be flatbuffers. Especially if you’re using multiple different languages. – Taekahn Jun 12 '22 at 21:25
  • @Taekahn im not so good at c++ right now looking at this page https://stackoverflow.com/questions/26255229/c-equivalent-of-bitconverter can i use that way on accepted answer on that page ? – draper.kaegan Jun 12 '22 at 21:29
  • 1
    If you’re not good at c++ and looking into bit manipulation, I think you’re in for a world of pain. As much as I love c++, it’s not beginner friendly if you want to tap into it’s more advanced features. – Taekahn Jun 12 '22 at 21:38
  • @Taekahn does that means i have to give up ? relly ? there is no way to simplfy and use that part of code ? – draper.kaegan Jun 12 '22 at 22:48
  • I’m not saying you have to give up. C++ is just a language that will let you shoot yourself in the foot. The best way to avoid doing that, imo, is to use a library instead of doing it yourself. Flatbuffers is a serialization library that can help you and it’s cross language as it was designed for network serialization – Taekahn Jun 12 '22 at 22:56
  • @Taekahn I %100 agree with you that how c++ causes brain damage :D (always developed c#, java, html and chip programming none c++) tried to find an unreal engine plugin to make that i couldnt, without plugin or c++ lib cant run it in unreal. Right now looking links posted on here: https://stackoverflow.com/questions/59155386/convert-byte-array-to-objects-c-c-sharp-bitconverter-in-c especially on bottom "BitConverter Class for C++" that guy said, tryn more. Thx for helping tho – draper.kaegan Jun 13 '22 at 00:36

0 Answers0