Results 1 to 4 of 4

Thread: Bytes

  1. #1
    Pinky1 is offline Member
    Join Date
    Sep 2012
    Posts
    1
    Rep Power
    0

    Default Bytes

    Why does this code print 0?
    public class A{
    public static void main(String str[]){
    byte b= (byte) 256;
    System.out.println(b);
    }}

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default Re: Bytes

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,003
    Blog Entries
    7
    Rep Power
    20

    Default Re: Bytes

    You can't stick 256 in a byte; it is too small for that value.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,586
    Rep Power
    23

    Default Re: Bytes

    The hex value of 256 is 0x100.
    The 00 is the part that is cast into the byte variable which holds 2 hex digits or 8 bits.
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. manipulating pcm bytes
    By Evanxtreme in forum Advanced Java
    Replies: 0
    Last Post: 07-14-2012, 09:16 AM
  2. Getting all the bytes in a file
    By Proshitness in forum New To Java
    Replies: 5
    Last Post: 06-15-2012, 11:17 PM
  3. How to write bytes above 128?
    By fatabass in forum New To Java
    Replies: 16
    Last Post: 01-20-2012, 10:37 PM
  4. Computing bytes
    By captainjack in forum New To Java
    Replies: 5
    Last Post: 10-28-2011, 01:22 AM
  5. how to know the number of bytes
    By gabriel in forum New To Java
    Replies: 2
    Last Post: 08-06-2007, 05:13 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •