p5.js byte() function Last Updated : 22 Aug, 2023 Comments Improve Suggest changes Like Article Like Report The byte() function in p5.js is used to convert the given string of number, number value or boolean into its byte representation. This byte number can only be whole number in between -128 to 127. The value outside of the range is converted into its corresponding byte representation.Syntax: byte(Value) Parameters: This function accepts single parameter Value which is to be converted into its byte representation. This value might be integer, float, string, boolean, negative or positive value and array of values. Return Value: It returns the converted byte representation.Below program illustrates the byte() function in p5.js:Example 1: This example uses byte() function to convert input elements into its byte representation. javascript function setup() { // Creating Canvas size createCanvas(600, 230); } function draw() { // Set the background color background(220); // Initializing some values let Value1 = 12; let Value2 = 12.5; let Value3 = -7.9; let Value4 = -6; let Value5 = "6"; let Value6 = 0; // Calling to byte() function. let A = byte(Value1); let B = byte(Value2); let C = byte(Value3); let D = byte(Value4); let E = byte(Value5); let F = byte(Value6); // Set the size of text textSize(16); // Set the text color fill(color('red')); // Getting byte representation text("Byte representation of value 12 is: " + A, 50, 30); text("Byte representation of value 12.5 is: " + B, 50, 60); text("Byte representation of value -7.9 is: " + C, 50, 90); text("Byte representation of value -6 is: " + D, 50, 110); text("Byte representation of string '6' is: " + E, 50, 140); text("Byte representation of string 0 is: " + F, 50, 170); } Output: Example 2: This example uses byte() function to convert input elements into its byte representation. javascript function setup() { // Creating Canvas size createCanvas(600, 140); } function draw() { // Set the background color background(220); // Initializing some values let Value1 = true; let Value2 = false; let Value3 = "Geeks"; let Value4 = [12, 3.6, -9.8, true, false]; // Calling to byte() function. let A = byte(Value1); let B = byte(Value2); let C = byte(Value3); let D = byte(Value4); // Set the size of text textSize(16); // Set the text color fill(color('red')); // Getting byte representation text("Byte representation of value 'true' is: " + A, 50, 30); text("Byte representation of value 'false' is: " + B, 50, 60); text("Byte representation of value 'Geeks' is: " + C, 50, 90); text("Byte representation of array of values are: " + D, 50, 110); } Output: Note: From the above examples, if the parameter is any fractional value then its output will be its integer equivalent i.e, a whole number between its range and string should be of number otherwise it gives output NaN i.e, not a number.Reference: https://p5js.org/reference/#/p5/byte Comment More infoAdvertise with us Next Article p5.js hex() function K Kanchan_Ray Follow Improve Article Tags : JavaScript Web Technologies JavaScript-p5.js Similar Reads p5.js | frames() Function The frames() function is an inbuilt function in p5.js library. This function is used to return the no of frames. There was a simple equation between samplesRate, duration, and frames. The equation is frames = samplesRate*duration. Syntax: frames() Note: All the sound-related functions only work when 1 min read p5.js char() function The char() function in p5.js is used to convert the given string or number value into its corresponding single-character string representation. If the input parameter is a string value then at first it gets converted into its integer equivalent internally after that its single-character string is re 3 min read p5.js hex() function The hex() function in p5.js is used to convert a number into its hexadecimal notation. Syntax: hex(Number) Parameters: This function accepts a parameter Number which are to be converted into its hexadecimal form. This parameter might also be an array of numbers. Return Value: It returns the converte 2 min read p5.js int() function The int() function in p5.js is used to convert the given boolean, integer, and float value into its integer representation. Syntax: int(ns) or int(n, radix) Parameters: This function accepts three types of the parameter which are listed below: n: It stores the value which needs to converts into i 3 min read p5.js unchar() function The unchar() function in p5.js is used to convert a single-character string into its corresponding integer representation. This function is just opposite to the char() function. Syntax: unchar(value) Parameters: This function accepts single parameter value which is to be converted into its correspon 2 min read p5.js loadBytes() Function The loadBytes() function is used to read the contents of a file or URL and return it as an object containing the series of bytes. The bytes can then be accessed by using the "bytes" property of the object. The file must be present in the sketch directory to be accessed. This method can support file 2 min read Like