Results 1 to 4 of 4
- 05-12-2011, 01:28 PM #1
Member
- Join Date
- May 2011
- Posts
- 7
- Rep Power
- 0
Combining multiple ints to 2 bytes.
Hi all,
I am trying to convert multiple ints to their binary values and that into a byte.
int version = 2; // (max 3) binary: 10
int padding = 0; // (max 1) binary: 0
int extension = 0; // (max 1) binary: 0
int cc = 7; // (max 15) binary: 0111
Together these ints would be: 1000 0111 And I want to convert that to a byte.
I have no clue how to do this.
I hope someone can help me, thanks in advance.
edit: I said 2 bytes in the title sorry... Should be 1 byte of course.Last edited by gonzalioz; 05-12-2011 at 01:31 PM. Reason: Wrong title, should be 1 byte.
- 05-12-2011, 02:12 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,605
- Blog Entries
- 7
- Rep Power
- 17
- 05-12-2011, 03:04 PM #3
Member
- Join Date
- May 2011
- Posts
- 7
- Rep Power
- 0
Ah thank you very much! I got a lot further:
int val = version << 6 | padding << 5 | extension << 4 | cc << 0;
System.out.println(Integer.toBinaryString(val));
It now prints the correct binary string. But the result is still an integer. Can you help me to convert val to a byte or convert the binary string to a byte? I couldn't find a java method that is something like Convert.toByte(val) like in .net.
Thanks!
- 05-12-2011, 03:12 PM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,605
- Blog Entries
- 7
- Rep Power
- 17
Similar Threads
-
Sum of odd ints 0-n
By falkon114 in forum New To JavaReplies: 7Last Post: 12-06-2010, 08:36 AM -
send multiple ints of data from the server to the client..
By lkcz in forum New To JavaReplies: 8Last Post: 09-24-2010, 03:34 AM -
Help with ints
By Insomniac Riot in forum New To JavaReplies: 5Last Post: 04-02-2010, 03:53 PM -
Combining these 2 projects
By fresh83 in forum New To JavaReplies: 14Last Post: 12-28-2009, 08:52 AM -
Help combining loops into 1 program.
By kewlgeye in forum New To JavaReplies: 5Last Post: 04-22-2008, 09:58 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks