Java bit operations error (convert to byte and convert back)



I'm trying to convert date of birth (three ints) to byte and convert it back but I'm having an issue. I have to convert it by using bit operations and send data over multicast server and receive it and change back to int. Server works fine, but bit operations are hard for me. What's the matter with the code:


Convert:


int D=12;
int M=9;
int Y=1983;
short DMY=0;
DMY = (short)(DMY | (D << 19));
DMY = (short)(DMY | (M << 15));
DMY = (short)(DMY | Y);
byte[] data = new byte[3];
data[0] = (byte)(DMY >>> 8 );
data[1]

Related to : Java bit operations error (convert to byte and convert back)
Java bit operations error (convert to byte and convert back)
Programming Languages

I'm trying to convert date of birth (three ints) to byte and convert it back but I'm having an issue. I have to convert it by using bit operations and send data over multicast server and receive it and change back to int. Server works fine, but bit operations are hard for me. What's the matter with the code:


Convert:


int D=12;
int M=9;
int Y=1983;
short DMY=0;
DMY = (short)(DMY | (D << 19));
DMY = (short)(DMY | (M << 15));
DMY = (short)(DMY | Y);
byte[] data = new byte[3];
data[0] = (byte)(DMY >>> 8 );
data[1]
Convert arbitrary size of byte[] to BigInteger[] and then safely convert back to exactly the same byte[], any clues?
Programming Languages

I believe conversion exactly to BigInteger[] would be optimal in my case. Anyone had done or found this written in Java and willing to share?


So imagine I have arbitrary size byte[] = {0xff,0x3e,0x12,0x45,0x1d,0x11,0x2a,0x80,0x81,0x45,0x1d,0x11,0x2a,0x80,0x81}
How do I convert it to array of BigInteger's and then be able to recover it back the original byte array safely?


ty in advance.


How do I convert Long to byte[] and back in java
Programming Languages

How do I convert a long to a byte[] and back in Java?
I'm trying convert a long to a byte[] so that I will be able to send the byte[] over a tcp connection. On the other side I want to take that byte[] and convert it back into a double.
Any tips would be appreciated.


Android Java create hex string and convert it to byte array and back
Programming Languages

I want to achieve something in my android application. I need to create a HEX representation of a String variable in my class and to convert it to byte array. Something like this :


String hardcodedStr = "SimpleText";
String hexStr = someFuncForConvert2HEX(hardcodedStr); // this should be the HEX string
byte[] hexStr2BArray = hexStr.getBytes();

and after that I want to be able to convert this hexStr2BArray to String and get it's value. Something like this :


String hexStr = new String(hexStr2BArray, "UTF-8");
String firstStr = someFuncConvertHEX2Str(hexStr); // the result must be : "Si


HD Wallpapers
3D
3D Abstract
City
Celebrities
Indian Celebrities
Cars
Travel
Girls
Animals Birds
Movies
Sports
Black White
Nature
Planes
Anime
Food Drink
Dreamy Fantasy
Architecture
Games
Space
Holidays
Flowers
Love
Artistic
Baby
Beach
Bikes Motorcycles
Macro
Computers
Vector
Funny
Army
Textures
Brands
Misc
Music
Other
Privacy Policy - Copyrights Notice - Feedback - Report Violation - RSS 2017 © bighow.org All Rights Reserved .