Re: binary conversion
K D <[email protected]>
| Newsgroups | gmane.comp.java.sun.servlet |
|---|---|
| Message-ID | <[email protected]> |
Hi Niall, In the example that you gave it, you are converting an integer into big and small endian right? I guess what I tried to ask was I have a 4 byte of data, and it is not stored in ascci format but rather in byte data only, so I have to read in data as byte array like this... byte num [] = new byte[4] int i = dataInputStream.read(num); , it is a byte array of data and not as an integer and because the byte was in Big endian format, I can't not convert it into a number using Integer or String object at all, it does not work, it produces unreadable character... --- Niall Gallagher <[email protected]> wrote: > >does anyone now how to convert binary integer (4 > byte) > >into decimal in Big-endian format? > > > int num = 1234; // 32 bits of an int > > int low = 0xffff0000 & num; // take first 16 bits > int high = 0x0000ffff & num; // take last 16 bits > > > int bigE = low ^ high; > int littleE = high ^ low; > > > I may be confused in regards to big and little > endian formats, its been a while....but you get the > idea. > > Niall > > ___________________________________________________________________________ > To unsubscribe, send email to [email protected] > and include in the body > of the message "signoff SERVLET-INTEREST". > > Archives: > http://archives.java.sun.com/archives/servlet-interest.html > Resources: > http://java.sun.com/products/servlet/external-resources.html > LISTSERV Help: > http://www.lsoft.com/manuals/user/user.html > __________________________________ Do you Yahoo!? The New Yahoo! Search - Faster. Easier. Bingo. http://search.yahoo.com ___________________________________________________________________________ To unsubscribe, send email to [email protected] and include in the body of the message "signoff SERVLET-INTEREST". Archives: http://archives.java.sun.com/archives/servlet-interest.html Resources: http://java.sun.com/products/servlet/external-resources.html LISTSERV Help: http://www.lsoft.com/manuals/user/user.html