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]

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]
Programming Languages

So I have a server and a client that communicate various data back
and fourth. Initially I had a complicated method that went through the
byte array and converted all of its variables and strings, one by one,
into what they were supposed to be. I learned I could put all of the
variables into an object and convert it to a byte array using

/>private static byte[] ObjectToByteArray2(Object obj)

{
if (obj == null)
return null;

BinaryFormatter bf = new BinaryFormatter();

MemoryStream ms = new MemoryStream();
bf.Serialize(ms,
obj);
return ms.ToArray();
}
C & C++ & C#

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.

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
Java

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.

Java
Ive got a question which is hopefully a very simple one: I have an />unmanaged DLL which has abstracted the memory management such that
I
can supply the malloc and free methods.
(ie)
void
__nogc * pascal myMalloc (struct tag_MemoryStream __nogc * pX, />size_t cb) ;
void pascal myFree (void __nogc * pX,
void *ptr) ;
.... Id like to implement these methods such that I
create and return a
managed array which is not GCed (ie
GC::KeepAlive()) and returned,
then when myFree is called, Id
like to convert this back again (ie
GC::ReRegisterForFinalize(
bytes )). Does anyone have an idea of how
to b
Development

- Technology - Languages
+ Webmasters
+ Development
+ Development Tools
+ Internet
+ Mobile Programming
+ Linux
+ Unix
+ Apple
+ Ubuntu
+ Mobile & Tablets
+ Databases
+ Android
+ Network & Servers
+ Operating Systems
+ Coding
+ Design Software
+ Web Development
+ Game Development
+ Access
+ Excel
+ Web Design
+ Web Hosting
+ Web Site Reviews
+ Domain Name
+ Information Security
+ Software
+ Computers
+ Electronics
+ Hardware
+ Windows
+ PHP
+ ASP/ASP.Net
+ C/C++/C#
+ VB/VB.Net
+ JAVA
+ Javascript
+ Programming
Privacy Policy - Copyrights Notice - Feedback - Report Violation 2018 © BigHow