Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

411
Views
Converting decimal to hexadecimal in bash script

I want to convert a decimal number (loop index number) in a bash script to hexadecimal to be used by another command. Something like:

for ((i=1; i<=100; i++))
do

     a=convert-to-decimal($i)
     echo "$a"

done

Where a should be hexadecimal with four digits and hex identifier. For example if value of i is 100, the value of a should be 0x0064. How to do it?

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

You can use printf.

$ printf "0x%04x" 100
0x0064

In your example you'd probably use a="$(printf '0x%04x' $i)".

over 4 years ago · Santiago Trujillo Report

0

That's what you're looking for

for i in seq 1 100; do printf '%x\n' $i done

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!