# Weird bug with this code

**URL:** <https://discourse.processing.org/t/weird-bug-with-this-code/16222>\
**Category:** Beginners\
**Created:** [December 7, 2019, 4:33pm UTC](https://discourse.processing.org/t/weird-bug-with-this-code/16222 "2019-12-07T16:33:58Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![yes](https://avatars.discourse-cdn.com/v4/letter/y/ea5d25/32.png) [@yes](https://discourse.processing.org/u/yes)\
**Post date:** [December 7, 2019, 4:33pm UTC](https://discourse.processing.org/t/weird-bug-with-this-code/16222/1 "2019-12-07T16:33:58Z")

</div>

```auto
void setup() {
  size(720,1000);
  background(0);
}

void draw() {
  textSize(18);
  text(ROMNAME,100,100);
}
`

String ROMNAME = "UNTITLED";

  
// Open a file and read its binary data 
byte[] openbytes1 = loadBytes("sketch_191207b/data/gameboy.gb");
{
  
}

Weird bug happening. How do I fix this?
```

---

<div class="post-metadata">

**Author:** ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)\
**Post date:** [December 7, 2019, 4:43pm UTC](https://discourse.processing.org/t/weird-bug-with-this-code/16222/2 "2019-12-07T16:43:12Z")

</div>

Are your byte range values in file from -128 to 127 ?  
Or maybe the return value = **null** , because no file was found.

---

<div class="post-metadata">

**Author:** ![yes](https://avatars.discourse-cdn.com/v4/letter/y/ea5d25/32.png) [@yes](https://discourse.processing.org/u/yes)\
**Post date:** [December 7, 2019, 4:49pm UTC](https://discourse.processing.org/t/weird-bug-with-this-code/16222/3 "2019-12-07T16:49:17Z")

</div>

I want my byte values to be 0 to 255

---

<div class="post-metadata">

**Author:** ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)\
**Post date:** [December 7, 2019, 5:13pm UTC](https://discourse.processing.org/t/weird-bug-with-this-code/16222/4 "2019-12-07T17:13:31Z")

</div>

It’s explained in the doc’s how to do that.  
[https://processing.org/reference/loadBytes\_.html](https://processing.org/reference/loadBytes_.html)

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [December 8, 2019, 6:54am UTC](https://discourse.processing.org/t/weird-bug-with-this-code/16222/5 "2019-12-08T06:54:51Z")

</div>

> [@yes](#):
>
> byte values to be 0 to 255

try also a

```auto
void setup() {
  numinfo();
}

void numinfo() {
  println( "__NUM INFO :");
  println( "byte "+Byte.SIZE+ " bit | min: "+Byte.MIN_VALUE+ "\t\t\t max: "+Byte.MAX_VALUE);
  println( "short "+Short.SIZE+ " bit | min: "+Short.MIN_VALUE+ "\t\t\t max: "+Short.MAX_VALUE);
  println( "int "+Integer.SIZE+" bit | min: "+Integer.MIN_VALUE+"\t\t max: " +Integer.MAX_VALUE);
  println( "long "+Long.SIZE+ " bit | min: "+Long.MIN_VALUE+ "\t max: " +Long.MAX_VALUE);
  println( "float "+Float.SIZE+ " bit | min: "+Float.MIN_VALUE+ "\t\t\t max: "+Float.MAX_VALUE);
  println( "double "+Double.SIZE+ " bit | min: "+Double.MIN_VALUE+ "\t\t\t max: "+Double.MAX_VALUE);
}

```

to get a idea about JAVA numbers

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [December 8, 2019, 11:04am UTC](https://discourse.processing.org/t/weird-bug-with-this-code/16222/6 "2019-12-08T11:04:54Z")

</div>

Hello,

This is expected behavior running the code you posted.

I made some corrections:

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/a/acb6155cc4503047b8f1da4c29b9fcff2bcc9adf.png)

![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/2/22bfa2a5c3075bcfc038668b1fe922154b0ea289.png)

You can convert (cast) the **bytes** to **ints** and 0 to 255 will be positive if that is what you require.

Go through this example and read the references:

```auto
byte[] nums1;
byte[] nums2;

void setup() 
  {
  size(100,100);
  background(0);
  
  nums1 = new byte[256];
  for(int i=0; i<256; i++)
    {
    nums1[i] = byte(i);  
    }

  saveBytes("numbers.dat", nums1);
  
  nums2 = loadBytes("numbers.dat");
    
  for(int i=0; i<256; i++)
    {
    println(nums2[i] +"\t\t"+ int(nums2[i&0xFF]) +"\t\t"+ hex(nums2[i]) +"\t\t"+ char(nums2[i&0xFF]));  
    }
  }

void draw() 
  {
  }

```

Some of the references:  
[https://processing.org/reference/intconvert\_.html](https://processing.org/reference/intconvert_.html)  
[https://processing.org/reference/charconvert\_.html](https://processing.org/reference/charconvert_.html)  
[https://processing.org/reference/hex\_.html](https://processing.org/reference/hex_.html)  
[https://processing.org/reference/println\_.html](https://processing.org/reference/println_.html)  
[https://processing.org/reference/byte.html](https://processing.org/reference/byte.html)  
[https://processing.org/reference/int.html](https://processing.org/reference/int.html)

🙂

---

<div class="post-metadata">

**Author:** ![yes](https://avatars.discourse-cdn.com/v4/letter/y/ea5d25/32.png) [@yes](https://discourse.processing.org/u/yes)\
**Post date:** [December 8, 2019, 3:12pm UTC](https://discourse.processing.org/t/weird-bug-with-this-code/16222/7 "2019-12-08T15:12:59Z")

</div>

I have just fixed it . Thanks anyways.
