Convert string to hexadecimal on command line
echo -n "Hello" | od -A n -t x1
Explanation:
- The
echo
program will provide the string to the next command. - The
-n
flag tells echo to not generate a new line at the end of the "Hello". - The
od
program is the "octal dump" program. (We will be providing a flag to tell it to dump it in hexadecimal instead of octal.) - The
-A n
flag is short for--address-radix=n
, with n being short for "none". Without this part, the command would output an ugly numerical address prefix on the left side. This is useful for large dumps, but for a short string it is unnecessary. - The
-t x1
flag is short for--format=x1
, with the x being short for "hexadecimal" and the 1 meaning 1 byte.
Conversion hex string into ascii in bash command line
This worked for me.
$ 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 <<< "$str")
$ echo "$hex"
6C6C6568A6F
Or:
$ hex=$(hexdump -e '"%X"' <<< "$str")
$ echo "$hex"
6C6C6568A6F
Careful with the '"%X"'
; it has both single quotes and double quotes.
Convert binary data to hexadecimal in a shell script
Perhaps use xxd
:
% 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=<str.txt
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?
Look at the error.
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({},{"_id":0,"Hex":1}))
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.
PS > "{0:x4}" -f ([int]"999")
03e7
Related Topics
How to Find Which Position a Word Is in a String
How to Find All Files Containing Specific Text on Linux
Bash Script Prints "Command Not Found" on Empty Lines
How to Recursively Grep All Directories and Subdirectories
Tool to Trace Local Function Calls in Linux
How to Build & Install Glfw 3 and Use It in a Linux Project
How to Rename All Folders and Files to Lowercase on Linux
How to Pipe Initial Input into Process Which Will Then Be Interactive
How to Count Lines in a Document
How to Find Out What All Symbols Are Exported from a Shared Object
Remove a Specific Character Using Awk or Sed
How to Change the Output Color of Echo in Linux
Using Openssl to Get the Certificate from a Server
Peak Memory Usage of a Linux/Unix Process
More Elegant "Ps Aux | Grep -V Grep"
How to Redirect the Output of the Time Command to a File in Linux
How to Setup & Run Phantomjs on Ubuntu
How to Open a Socket and Pass It to Another Process in Linux