Linux text to hex

Convert String to Hexadecimal on Command Line

Conversion hex string into ascii in bash command line

$ echo 54657374696e672031203220330 | xxd -r -p
Testing 1 2 3$

-r tells it to convert hex to ascii as opposed to its normal mode of doing the opposite

-p tells it to use a plain format.

bash ascii to hex

$ str="hello"
$ hex=$(xxd -pu $ echo "$hex"
6C6C6568A6F
$ hex=$(hexdump -e '"%X"' $ echo "$hex"
6C6C6568A6F

Careful with the ‘»%X»‘ ; it has both single quotes and double quotes.

Convert binary data to hexadecimal in a shell script

% xxd -l 16 -p /dev/random
193f6c54814f0576bc27d51ab39081dc

Convert hex string to ASCII string in Windows batch file

Use certutil tool, see certutil /? for more info.

setlocal enabledelayedexpansion
set "hex=4C6F67696300000000000000"
echo !hex!> temp.hex
call certutil -decodehex temp.hex str.txt >nul
set /p str=echo:
( del temp.hex & del str.txt )>nul
echo Your decoded string is:"!str!".
endlocal
exit /b 0

Is there any way to convert the hex code from string to hex colour which discord.py supports?

TypeError: Expected discord.Colour, int, or Embed.Empty

An int would suffice, no need for extra conversions.

@client.command()
async def testing(ctx):
# color = lgd.hexConvertor(colorCollection.find(<>,))
c = "0xFFFFFF"
int_colour = int(c,16)
await ctx.send(embed = discord.Embed(description = "testing",color = int_colour))

Ascii/Hex convert in bash

The reason is because hexdump by default prints out 16-bit integers, not bytes. If your system has them, hd (or hexdump -C ) or xxd will provide less surprising outputs — if not, od -t x1 is a POSIX-standard way to get byte-by-byte hex output. You can use od -t x1c to show both the byte hex values and the corresponding letters.

If you have xxd (which ships with vim), you can use xxd -r to convert back from hex (from the same format xxd produces). If you just have plain hex (just the ‘4161’, which is produced by xxd -p ) you can use xxd -r -p to convert back.

DOS command to format string to hex value

Forget about Peak Oil, what about Peak DOS? It’s time to look to the future. And the future is PowerShell.

Источник

How to convert file data to plain hex?

How to easily convert to/from plain machine-readable hexadecimal data (without any paddings/offsets/character view) with xdd or hexdump ? I’m tired of digging of some special format strings (and finding out that it suddenly starts wrapping lines after N characters or skip lines) or writing Perl one-liners every time. Why is it not as simple as base64 / base64 -d ?

Читайте также:  Vmware общая папка windows linux

3 Answers 3

If you get tired of writing this every time, create an alias.

I’m tired of looking at man page and gettings confused either by necessity to compose hexdump’s formt strings or by xxd’s «postscript» thing. (Is this «postscript» something about printers or about letters?)

@Vi, think of -p as «plain». I surmise the Postscript comment is because the Postscript language allows for in-line data (typically images) encoded exactly this way. So Postscript programmers may use xxd to convert binary images into a convenient form for embedding in a Postscript file.

How to easily convert to/from plain machine-readable hexadecimal data

$ xxd -plain test.txt > test.hex $ xxd -plain -revert test.hex test2.txt $ diff test.txt test2.txt $
$ xxd -plain test.txt > test.hex 

This writes a hex encoding of the data in test.txt into new file test.hex. The -p or -plain option makes xxd use «plain» hex format with no spaces between pairs of hex digits (i.e. no spaces between byte values). This converts «abc ABC» to «61626320414243». Without the -p it would convert the text to a 16-bit word oriented traditional hexdump format, which is arguably easier to read but less compact and therefore less suitable as a transmission format and slightly harder to reverse.

$ xxd -plain -revert text.hex test2.txt 

This uses the -r or -revert option for reverse operation. The -plain option is used again to indicate that the input hex file is in plain format.

I make the output filename different from the original filename so we can later compare the results with the original file.

The diff command outputs nothing — this means there is no difference between the original and reconstituted file contents.

I’m tired of digging of some special format strings

Use alias or declare functions in your .profile to create mnemonics so you don’t have to remember or dig about in man pages.

or just remember -plain and -revert .

Yes, there are new-line characters in the output. You want to avoid that. You can use the -c or -cols option to specify how long you want the output lines to be to attempt to avoid line-wrapping of the output. -c 0 gives the default length and the man page suggests 256 is the limit but it seems to work beyond that.

$ xxd -plain -cols 9999 test.txt > test.hex $ wc test.txt test.hex 121 880 4603 test.txt 1 1 9207 test.hex 

The wc wordcount command tells us how many lines, words and characters are in each file.

So 121 lines (880 words, 4603 bytes) of ASCII text were encoded as 1 line of hex digits.

Источник

Thread: Command needed to convert text to hex

Metacarpal is offlineSkinny Soy Caramel Ubuntu

Join Date May 2006 Location Brooklyn, NY, USA Beans 629 —> Beans 629 Distro Ubuntu 7.10 Gutsy Gibbon

Читайте также:  Образ linux через acronis

Command needed to convert text to hex

Does anyone know a standard unix/linux command to convert a text string to hexidecimal?

I’ve tried hexdump, but I need a single, unified hex string rather than the broken-up format hexdump gives.

If there is a command to do this without my having to parse hexdump output, that would be great. (I’d also be happy with perl code, though I’m less adept at perl than unix shell.)

[h2o] is offlineTea Glorious Tea!

Re: Command needed to convert text to hex

The problem is that string->hexadecimal can be done in a great number of ways depending on encoding.

I don’t know of any standard command, but it should be pretty easy to code in whatever language you prefer. Loop through all characters and then translate to integer which you then display as hexadecimal.

xlinuks is offlineQuad Shot of Ubuntu

Re: Command needed to convert text to hex

If I understand you correctly you could use ghex2 and then save the hex as html, just be sure to save into a separate folder.

Wybiral is offlineUbuntu addict and loving it

Re: Command needed to convert text to hex

You could always hack up a small python program for it.

in_string = raw_input("Text: ") out_string = "" for c in in_string: out_string += hex(ord(c)).split("x")[1] + " " print(out_string)

bashologist is offlineCookies and cream

Re: Command needed to convert text to hex

nanotube is offlineUbuntu addict and loving it

Join Date Jan 2006 Location Philadelphia Beans 4,076 —> Beans 4,076 Distro Ubuntu 8.10 Intrepid Ibex

Re: Command needed to convert text to hex

here’s another solution in python (sample session shown below)

>>> import binascii >>> binascii.hexlify('blabla') '626c61626c61'

bogolisk is offlineGee! These Aren’t Roasted!

Re: Command needed to convert text to hex

QuoteOriginally Posted by Metacarpal View Post

Does anyone know a standard unix/linux command to convert a text string to hexidecimal?

I’ve tried hexdump, but I need a single, unified hex string rather than the broken-up format hexdump gives.

If there is a command to do this without my having to parse hexdump output, that would be great. (I’d also be happy with perl code, though I’m less adept at perl than unix shell.)

Metacarpal is offlineSkinny Soy Caramel Ubuntu

Join Date May 2006 Location Brooklyn, NY, USA Beans 629 —> Beans 629 Distro Ubuntu 7.10 Gutsy Gibbon

Re: Command needed to convert text to hex

QuoteOriginally Posted by bogolisk View Post

  • Site Areas
  • Settings
  • Private Messages
  • Subscriptions
  • Who’s Online
  • Search Forums
  • Forums Home
  • Forums
  • The Ubuntu Forum Community
    1. Ubuntu Official Flavours Support
      1. New to Ubuntu
      2. General Help
      3. Installation & Upgrades
      4. Hardware
      5. Desktop Environments
      6. Networking & Wireless
      7. Multimedia Software
    2. Ubuntu Specialised Support
      1. Ubuntu Development Version
      2. Security
      3. Virtualisation
      4. Ubuntu Servers, Cloud and Juju
        1. Server Platforms
        2. Ubuntu Cloud and Juju
      5. Gaming & Leisure
        1. Emulators
      6. Wine
      7. Development & Programming
        1. Packaging and Compiling Programs
        2. Development CD/DVD Image Testing
        3. Ubuntu Application Development
        4. Ubuntu Dev Link Forum
        5. Programming Talk
        6. Repositories & Backports
          1. Ubuntu Backports
            1. Bug Reports / Support
      8. System76 Support
      9. Apple Hardware Users
    3. Ubuntu Community Discussions
      1. Ubuntu, Linux and OS Chat
        1. Recurring Discussions
        2. Full Circle Magazine
      2. The Cafe
        1. Cafe Games
      3. Market
      4. Mobile Technology Discussions (CLOSED)
      5. Announcements & News
      6. Weekly Newsletter
      7. Membership Applications
      8. The Fridge Discussions
      9. Forum Council Agenda
      10. Forum Feedback & Help
        1. Request a LoCo forum
      11. Resolution Centre
    4. Other Discussion and Support
      1. Other OS Support and Projects
        1. Other Operating Systems
          1. Ubuntu/Debian BASED
          2. Debian
          3. MINT
          4. Arch and derivatives
          5. Fedora/RedHat and derivatives
          6. Mandriva/Mageia
          7. Slackware and derivatives
          8. openSUSE and SUSE Linux Enterprise
          9. Mac OSX
          10. PCLinuxOS
          11. Gentoo and derivatives
          12. Windows
          13. BSD
          14. Any Other OS
      2. Assistive Technology & Accessibility
      3. Art & Design
      4. Education & Science
      5. Documentation and Community Wiki Discussions
      6. Tutorials
        1. Outdated Tutorials & Tips
      7. Ubuntu Women
      8. Ubuntu LoCo Team Forums
        1. Americas LoCo Teams
          1. Argentina Team
            1. Software
            2. Hardware
            3. Comunidad
          2. Arizona Team — US
          3. Arkansas Team — US
          4. Brazil Team
          5. California Team — US
          6. Canada Team
          7. Centroamerica Team
          8. Chile Team
            1. Comunidad
            2. Hardware
            3. Software
            4. Instalaci�n y Actualizaci�n
          9. Colombia Team — Colombia
          10. Georgia Team — US
          11. Illinois Team
          12. Indiana — US
          13. Kentucky Team — US
          14. Maine Team — US
          15. Minnesota Team — US
          16. Mississippi Team — US
          17. Nebraska Team — US
          18. New Mexico Team — US
          19. New York — US
          20. North Carolina Team — US
          21. Ohio Team — US
          22. Oklahoma Team — US
          23. Oregon Team — US
          24. Pennsylvania Team — US
          25. Peru Team
          26. Texas Team — US
          27. Uruguay Team
          28. Utah Team — US
          29. Virginia Team — US
          30. West Virginia Team — US
        2. Asia and Oceania LoCo Teams
          1. Australia Team
          2. Bangladesh Team
          3. Hong Kong Team
          4. Myanmar Team
          5. Philippine Team
          6. Singapore Team
        3. Europe, Middle East, and African (EMEA) LoCo Teams
          1. Albania Team
          2. Catalan Team
          3. Portugal Team
          4. Egypt Team
          5. Georgia Team
          6. Ireland Team — Ireland
          7. Kenyan Team — Kenya
          8. Kurdish Team — Kurdistan
          9. Lebanon Team
          10. Morocco Team
          11. Saudi Arabia Team
          12. Sudan Team
          13. Tunisia Team
        4. Other Forums & Teams
        5. LoCo Archive
          1. Afghanistan Team
          2. Alabama Team — US
          3. Alaska Team — US
          4. Algerian Team
          5. Andhra Pradesh Team — India
          6. Austria Team
          7. Bangalore Team
          8. Bolivia Team
          9. Cameroon Team
          10. Colorado Team — US
          11. Connecticut Team
          12. Costa Rica Team
          13. Delhi Team
          14. Ecuador Team
          15. El Salvador Team
          16. Florida Team — US
          17. Galician LoCo Team
          18. Greek team
          19. Hawaii Team — US
          20. Honduras Team
          21. Idaho Team — US
          22. Iowa Team — US
          23. Jordan Team
          24. Kansas Team — US
          25. Libya Team
          26. Louisiana Team — US
          27. Maryland Team — US
          28. Massachusetts Team
          29. Michigan Team — US
          30. Missouri Team — US
          31. Montana Team — US
          32. Namibia Team
          33. Nevada Team — US
          34. New Hampshire Team — US
          35. New Jersey Team — US
          36. Northeastern Team — US
          37. Panama Team
          38. Paraguay Team
          39. Qatar Team
          40. Quebec Team
          41. Rhode Island Team — US
          42. Senegal Team
          43. South Carolina Team — US
          44. South Dakota Team — US
          45. Switzerland Team
          46. Tamil Team — India
          47. Tennessee Team — US
          48. Trinidad & Tobago Team
          49. Uganda Team
          50. United Kingdom Team
          51. US LoCo Teams
          52. Venezuela Team
          53. Wales Team
          54. Washington DC Team — US
          55. Washington State Team — US
          56. Wisconsin Team
          57. Yemen Team
          58. Za Team — South Africa
          59. Zimbabwe Team
Читайте также:  Linux citrix receiver install

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Источник

Оцените статью
Adblock
detector