p5.js中的unhex()函數用於將任何輸入的十六進製數字的字符串表示形式轉換為其等效的整數值。
用法:
unhex(String)
參數:此函數接受參數String,該參數是十六進製數,並將轉換為等效的整數值。此參數也可以是十六進製字符串的數組。
返回值:它返回轉換後的整數表示形式。
以下示例程序旨在說明p5.js中的unhex()函數。
示例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); 
  
}輸出:

示例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); 
  
}輸出:

參考: https://p5js.org/reference/#/p5/unhex
相關用法
- d3.js d3.hsl()用法及代碼示例
 - PHP cos( )用法及代碼示例
 - p5.js sin()用法及代碼示例
 - p5.js tan()用法及代碼示例
 - PHP pos()用法及代碼示例
 - PHP key()用法及代碼示例
 - p5.js log()用法及代碼示例
 - p5.js cos()用法及代碼示例
 - p5.js day()用法及代碼示例
 - PHP each()用法及代碼示例
 - p5.js second()用法及代碼示例
 - PHP each()用法及代碼示例
 
注:本文由純淨天空篩選整理自Kanchan_Ray大神的英文原創作品 p5.js | unhex() function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
