Weird bug with this code

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?
1 Like

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

1 Like

I want my byte values to be 0 to 255

It’s explained in the doc’s how to do that.
https://processing.org/reference/loadBytes_.html

3 Likes

try also a

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

2 Likes

Hello,

This is expected behavior running the code you posted.

I made some corrections:

image

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:

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/charconvert_.html
https://processing.org/reference/hex_.html
https://processing.org/reference/println_.html
https://processing.org/reference/byte.html
https://processing.org/reference/int.html

:slight_smile:

1 Like

I have just fixed it . Thanks anyways.

1 Like