p5.js | unhex() function

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:

filter_none

edit
close

play_arrow

link
brightness_4
code

function setup() {
  
    // Creating Canvas size
    createCanvas(500, 100);
}
  
function draw() {
  
    // Set the background color 
    background(220);
  
    // Initializing some strings
    let String1 = "F";
    let String2 = "FF";
  
    // Calling to unhex() function.
    let A = unhex(String1);
    let B = unhex(String2);
  
    // Set the size of text 
    textSize(16);
  
    // Set the text color 
    fill(color('red'));
  
    // Getting integer equivalent
    text("Integer equivalent of hexadecimal string 'F' is: "
         + A, 50, 30);
    text("Integer equivalent of hexadecimal string 'FF' is: "
         + B, 50, 60);
  
}

chevron_right


Output:

Example-2:

filter_none

edit
close

play_arrow

link
brightness_4
code

function setup() {
  
    // Creating Canvas size
    createCanvas(650, 100);
}
  
function draw() {
  
    // Set the background color 
    background(220);
  
    // Initializing some strings
    let String1 = ["F", "A", "C"];
    let String2 = ["FF", "AC", "DE"];
  
    // Calling to unhex() function.
    let A = unhex(String1);
    let B = unhex(String2);
  
    // Set the size of text 
    textSize(16);
  
    // Set the text color 
    fill(color('red'));
  
    // Getting integer equivalent
    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);
  
}

chevron_right


Output:

Reference: https://p5js.org/reference/#/p5/unhex



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.