p5.js unhex() function
Last Updated :
22 Aug, 2023
The unhex() function in p5.js is used to convert a string representation of any input hexadecimal number to its equivalent integer value.
Syntax:
unhex(String)
Parameters: This function accepts a parameter String which is a hexadecimal number and is to be converted into its integer equivalent value. This parameter might also be an array of strings of the hexadecimal numbers.
Return Value: It returns the converted integer representation.
Below program illustrates the unhex() function in p5.js.
Example-1:
function setup() {
createCanvas(500, 100);
}
function draw() {
background(220);
let String1 = "F" ;
let String2 = "FF" ;
let A = unhex(String1);
let B = unhex(String2);
textSize(16);
fill(color( 'red' ));
text( "Integer equivalent of hexadecimal string 'F' is: "
+ A, 50, 30);
text( "Integer equivalent of hexadecimal string 'FF' is: "
+ B, 50, 60);
}
|
Output:
Example-2:
function setup() {
createCanvas(650, 100);
}
function draw() {
background(220);
let String1 = [ "F" , "A" , "C" ];
let String2 = [ "FF" , "AC" , "DE" ];
let A = unhex(String1);
let B = unhex(String2);
textSize(16);
fill(color( 'red' ));
text( "Integer equivalent of array of hexadecimal strings" +
" ['F', 'A', 'C'] is: "
+ A, 50, 30);
text( "Integer equivalent of array of hexadecimal strings" +
" ['FF', 'AC', 'DE'] is: "
+ B, 50, 60);
}
|
Output:
Reference: https://p5js.org/reference/#/p5/unhex
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...