PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, August 7, 2022

[FIXED] How to convert a big decimal to hex in bash?

 August 07, 2022     bash, decimal, hex     No comments   

Issue

I need to convert a very big number in its hex form (no spaces, no anything e.g. 8ac7230489e80001). Using printf gives an out of range error.

printf '%x\n' "24267339429148234667523"

-bash: printf: warning: 24267339429148234667523: Numerical result out of range
ffffffffffffffff

I tried other methods (python), but it seems they only give a string output. I still need it to be a number. Is it possible to handle numbers larger like this?


Solution

You can use the bc utility:

bc <<< 'obase=16;24267339429148234667523'


Answered By - M. Nejat Aydin
Answer Checked By - Cary Denson (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing