• 0

[Java]Binary int to byte


Question

Hi guys.

This is my final option, I have been trying for a few hours to do this and still haven't managed!

Basically I have a 6 digit int that represents a six bit binary number, say 010000. I want to cast this to the equivalent byte value, in this case 16.

Any help appreciated.

Dougal.

Link to comment
Share on other sites

4 answers to this question

Recommended Posts

  • 0

Woo! Worked it out. Had my brackets in the wrong place.

For all those interested......

answerAsByte = (byte)integerNumber;

soooo simple! :D

Dougal.

Link to comment
Share on other sites

  • 0

I made something like that today @ college.

/**
 * Integer
 * 
 * @author Tiago F. Silva
 * @version IP 2004/2005
 */

import java.util.Scanner;

public class Integer {

 ? ? ? public static void main(String[] args) {

 ? ? ? Scanner kthx = new Scanner(System.in);
 ? ? ? System.out.println (Integer.valueOf(kthx.nextLine(), 2));
 ? ? ? }
}

edit: ahah, you found it! g;)d for you ;)

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.