hex

Use vim to search by hex code

I need to clean up a file. We have an xml parser that runs on it that is failing due to an escape character (0x1B) in the file. How do I use vim to find where in the file that character is so I can remove it? Example file: <?php echo "Hello, world.\n"; ?> After conversion: 0000000: 0a3c 3f70 6870 0a65 63...

Python, int to hex string

I want to take an integer (that will be <= 255), to a hex string representation eg: I want to pass in 65 and get out '\x65', or 255 and get '\xff' I've tried doing this with the struct.pack('c', 65), but that chokes on anything above 9 since it wants to take in a single character string. Thanks, ...

Code Golf: C#: Convert ulong to Hex String

I tried writing an extension method to take in a ulong and return a string that represents the provided value in hexadecimal format with no leading zeros. I wasn't really happy with what I came up with... is there not a better way to do this using standard .NET libraries? public static string ToHexString(this ulong ouid) { string t...

Printing the hex value of an array to a string using C++

Using standard C++ I/O (such as std::cout), is it possible to "print" the value of an array (however long) into a string? For example, say I have the following array: unsigned long C = {0x497fecf2, 0xfa989ea3, 0xd594974e}; I'd like to be able to print those values into a string, and then remove the "0x" from them. From another SO que...

Convert hex data string to NSData in Objective C (cocoa)

Hi, fairly new iPhone developer here. Building an app to send RS232 commands to a device expecting them over a TCP/IP socket connection. I've got the comms part down, and can send ASCII commands fine. It's the hex code commands I'm having trouble with. So lets say I have the following hex data to send (in this format): \x1C\x02d\x00\x...

css style hex strings and Color.decode

this article suggests you can use Color c = Color.decode("FF0096"); however this understandably throws an exception Caused by: java.lang.NumberFormatException: For input string: "FF0096" at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48) at java.lang.Integer.parseInt(Integer.java:449) at java.la...

Python 3.1.1 string to hex

I am trying to use str.encode() but I get >>> "hello".encode(hex) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: must be string, not builtin_function_or_method I have tried a bunch of variations and they seem to all work in Python 2.5.2, so what do I need to do to get them to work in Python 3.1? ...

char '0x8' what character is this?

I have a large amount of data in a database. When I attempt to read a certain portion of the data and generate some xml and send it to a webservice I get the following exception... The char '0x8' in 'java.lang.IllegalArgumentException'. I'm guessing it is some bad data, as it has worked perfectly for about 7 months but now some user...

Actionscript 3.0 Translating HEX to ARGB

i'm studying getPixel32() and the Bitmap and Bitmap Data classes. Basically, i'd like to know how to output a simple trace of an ARGB from a hexadecimal value. as an aside, i'm under the impression, which i assume/hope is wrong, that hexadecimal values can't produce as many colors as RGBA values. perhaps "web safe" has thrown me off...

Negate Unsigned Number in Bash

I have a number (hex) and I want the one's complement of it. For example if X = 20 I want bash to perform a negation and return Y = ~X = DF. It doesn't have to be in bash, but it should use a common command line tool that I can wrap into a script. Also note that the numbers should all be unsigned and I'd prefer they don't overflow the...

Converting to Base 10

Question Let's say I have a string or array which represents a number in base N, N>1, where N is a power of 2. Assume the number being represented is larger than the system can handle as an actual number (an int or a double etc). How can I convert that to a decimal string? I'm open to a solution for any base N which satisfies the abov...

easy hex/float conversion

I am doing some input/output between a c++ and a python program (only floating point values) python has a nice feature of converting floating point values to hex-numbers and back as you can see in this link: http://docs.python.org/library/stdtypes.html#additional-methods-on-float Is there an easy way in C++ to to something similar? and...

PHP: Convert shorthand Hex Colors to Regular

I'm trying to make a function that will take short hand hex color to the long hex color. For example if someone submits "f60" it will convert to "ff6600". I understand I need to repeat each number as itself, but what is the most efficient way to do this? Thank you. ...

Add Hexadecimal Header Info to JPEG File Using Java

I need to add header info to a JPEG file in order to get it to work properly when shared on some websites, I've tracked down the correct info through a lot of Hex digging, but now I'm kind of stuck trying to get it into the file. I know where in the file it needs to go, and I know how long it is, my problem is that RandomAccessFile just...

How to convert an ASCII HEX character to it's value (0-15)?

I am writing a string parser and the thought occurred to me that there might be some really interesting ways to convert an ASCII hexadecimal character [0-9A-Fa-f] to it's numeric value. What are the quickest, shortest, most elegant or most obscure ways to convert [0-9A-Fa-f] to it's value between 0 and 15? Assume, if you like, that the...

double to hex. How It's Made?

157,453796 = hex 18068A 157,455093 = hex 180697 71,5037 = hex E91D00 71,506104 = hex E93500 71,507103 = hex E93F00 0 = hex 000000 I know exactly what it is not IEEE 754 ...

PHP - Rotate a HEX color value (eg swap all colors with "next" hex)

I have a set of hex values in an array in PHP. On my page, I have a slider which the user can "slide" to return a value between 1-100. I want to then, based on this slider value, swap all the colors in the array based on the colors "next" color based on the position in the array. An example of the same sort of thing would be like in phot...

How to convert a string color to its hex code or RGB value?

Hello all, I am not sure if its possible but I would like to create some sort of function where you pass in a string such as "yellow" or "green" and it returns its hex code or the range of hex codes that greens or yellows fit into. Is this possible in PHP? If not possible, I am willing to try anything else that can do this! Thanks all...

How can I make a fixed hex editor?

So. Let's say I were to make a hex editor to edit... oh... let's say a .DLL file. How can I edit a .DLL file's hex by using C# or C++? And for the "fixed part", I want to make it so that I can browse from the program for a specific .DLL, have some pre-coded buttons on the programmed file, and when the button is pressed, it will automatic...

Colour Name to RGB/Hex/HSL/HSV etc

Hello all, I have come across this great function/command. Colour to RGB, you can do this: col2rgb("peachpuff") //returns hex It will return one hex value. I want to extend this using Perl, Python or PHP but I want to be able to pass in, for example, "yellow" and the function returns all types of yellows - their hex/rgb/?/etc value. ...