Home Java Java-conversion Convert Long To Byte

Related Tutorials


 
 

Share on Google+Share on Google+

Convert Long To Byte

Advertisement
In this section, we are going to convert a long type data into a byte.

Convert Long To Byte 

     

In this section, we are going to convert a long type data into a byte. The following program provides you the functionality to convert into a long to byte.

Code Description:

This program  defines a class named is "LongToByte". This class wraps a value of the primitive type long in an object. This is a long type object that contains a single. For converting this, you simply use the type casting process like:  byte bValue = (byte) num; statement and it converted into a byte format.

Here is the code of this program given below:

import java.io.*;
import java.lang.*;

public class LongToByte {
  public static void main(String[] argsthrows IOException{
  BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
  System.out.println("Enter the long value:");
  String s = bf.readLine();
  long num = Long.parseLong(s);
  byte bValue = (bytenum;
  System.out.println("Byte is:"+ num);
  }
}

Download this program:

Output of this program given below.

C:\corejava>java LongToByte
Enter the long value:
65
Byte is:65
C:\corejava> _
Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: July 4, 2007

Related Tutorials

Discuss: Convert Long To Byte   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:1
Mustafa
January 31, 2012
Dont' right

That don't work with values which is greater than 255?! But long is represented up to 32 bytes
DMCA.com