Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
Java has a byte primitive data type.
https://docs.oracle.com/javase/...
Java supports all of the bitwise operators. idk what you mean by "it doesn't support" like it really does. I did a lot of work parsing binary data with java, it's all there.
Also look into ByteBuffer if you're streaming large amounts of data.
Declare your masks with byte b = 0b00001010; mask them with & ^ | etc. -
ddephor44386y@lindgrenj6 Yes, Java has a byte type, but internally it is a signed value and that has some drawbacks. Try
byte test = 0x7F;
byte test2 = 0x81;
and see what happens (hint: the java compiler won't let you do the latter this way)
But this is a limitation of the JVM, therefore Kotlin inherited this issue. -
@ddephor well the latter makes sense, it says right there in the docs that a byte is equivalent to a short. Ranges of -127 - 127 signed by two's compliment. Java doesn't have unsigned integer types like C unfortunately, but that doesn't mean it _doesn't support_ binary.
-
It is weird and Gosling's reasoning behind it is pretty fucky(states that the most users of unsigned arithmetic are C devs and they don't understand it completely, whatever the fuck he wanted to say with that beats me)
And a hacky bs solution is people using char(which is a 16 bit character) as an unsigned integer which still does not let you do unsigned arithmetic.
Fucky as all hell.
Furthermore JDK8 has new methods for Long and Integer(which are not primitives but actual classes....fuck me) which do have certain methods to work around this, i don't know if that is of any help or you have looked into it already.
Sorry bro. I tried. But if that doesn't work at least we share the same frustrations. It really makes a language feel dumbed down -
Root797796y@lindgrenj6 signed short != byte, though.
A byte is 0..255; if you want a signed value, use something else, like a signed short! -
Awlex177456yI don't really get the point of this rant. Open your BufferedInputStream, get your byte (unsigned or not) and assemble your structures with binary operators. If you are concerned about the signs, use operators that ignore it. Basically all except '<<' and '>>' iirc
@ddephor Probably because you didn't cast it to a byte. You get (obviously) -127 afterwards. -
ddephor44386y@lindgrenj6 It's documented, sure, but that doesn't make it any better. Who came up with the *%&! idea to support only signed values within the JVM?
And yes, there are workarounds, like fiddling through bigger sized types, cast and convert it around a few times, but that's just complex bullshit. I want to access the complete, uninterpreted byte, all 8 bits as is. And that's no esoteric use case, binary data structures are everywhere. -
ddephor44386y@AleCx04 I didn't have a look at JDK8, I just found a description, that Kotlin 1.3 will have unsigned types as experimental feature.
No wonder C/C++ is everywhere. Although I just touched the surface of Android development I already thought of doing the base logic in C++ and just the UI/UX stuff in Kotlin/Java -
ddephor44386y@Awlex I don't want -127, I don't want 255 or 0 or 42 or whatever. I want the plain, uninterpreted 8 bits to use and manipulate.
Not every byte holds an integer, this is already an interpretation of the content of that byte.
And I don't want to think about how to use a byte type here and there just because the only way a language handles its content is an akward way
I don't get it.
I tried Kotlin on Android just for fun, and it doesn't support binary data handling, not even unsigned types until the newest version. Java suffers from the same disease.
How does one parse and process binary data streams on such a high end system? Not everything is highlevel XML or JSON today.
And it's not only an Android issue.
Python has some support for binary data, and it's powerful, but not comfortable.
I tried Ruby, Groovy, TCL, Perl and Lua, and only Lua let's you access data directly without unnecessary overhead.
C# is also akward when it comes to data types less than the processer register width.
How hard can it be to access and manipulate data in its natural and purest form?
Why do the so called modern programming language ignore this simple aspect that is needed on an everyday basis?
rant
8 bit ought to be enough for everyone