Monday, November 18, 2024
Google search engine
HomeLanguagesJavascriptp5.js unhex() function

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:




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);
  
}


Output:

Example-2:




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);
  
}


Output:

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

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

RELATED ARTICLES

Most Popular

Recent Comments