hex

Converting from hex to binary without losing leading 0's python

I have a hex value in a string like h = '00112233aabbccddee' I know I can convert this to binary with: h = bin(int(h, 16))[2:] However, this loses the leading 0's. Is there anyway to do this conversion without losing the 0's? Or is the best way to do this just to count the number of leading 0's before the conversion then add it in...

C: save received Winsock packet to file as hex

I need to do what most packet monitoring programs do (Wireshark, tcpdump, etc.). When data is received through Winsock, I just need to convert the packet to a hex representation and save it to file. The data is just a simple char array. I've tried lots of things like sprintf but with no luck. I also don't want to use itoa since it's no...

Reading in Intel Hex file for sorting C++

I need to read in an Intel Hex file which looks something like this: :0300000002F8D42F :07000300020096000000005E :07000B000200B50000000037 :030013000200D414 :03001B000200F3ED (Yes, some lines are missing and sometimes 1 line only contains 1 byte) The : is the start code First 2 bytes is the byte count Next 4 are the address in mem...

How can I write a hard drive sector as reserved?

I am hex editing a hard disk and I would like to mark some hard drive sectors as reserved so that they are not overwritten by Windows (Vista or 7). I think this is possible, since during a defrag, the disk says that there are some sectors that aren't movable. How can I do this? ...

C#: Why isn't Guid.ToString("n") the same as a hex string generated from a byte array of the same guid?

Consider the following unit test: [TestMethod] public void TestByteToString() { var guid = new Guid("61772f3ae5de5f4a8577eb1003c5c054"); var guidString = guid.ToString("n"); var byteString = ToHexString(guid.ToByteArray()); Assert.AreEqual(guidString, byteString); } private String To...

C# Hex Mask for maskedtextbox input

I'm trying to set a hex mask for a textbox. So that only valid hex numbers can be entered. (And ',' and 'ENTER') It almost works. So far it will only allow small letters from a-f and numbers 0-9, but I can still enter capital letters GHIJKLM. (At first, when program is started it seems to accept one char ex k, but after it has excepted ...

XSLT is converting my hex attributes to something else, how do I stop it?

I'm trying to transform one xml file to output another xml file, and I need the attribute "account" to be output identically to how it appears below. I have a bunch of these values in the file, most are not working. For values of account like 0x0406 it is output as 0.0.06. But for values like 0x002d it leaves them alone and they come t...

Generating gradients from a hexcode or RGB in PHP/jQuery?

Hello, I'm trying to figure out how to write a function that programmatically retrieves a background-color css attribute and creates two outputs (one slightly darker than the background-color, one slightly lighter). The idea is being able to generate a very basic linear gradient from a single color selection. Anyone have any ideas? ...

C++: Getting hex unexpectedly when printing array

Hi I am declaring an array using new int *a = NULL; a = new int[10]; a[0] = 23; a[1] = 43; a[2] = 45; a[3] = 76; a[4] = 34; a[5] = 85; a[6] = 34; a[7] = 97; a[8] = 45; a[9] = 22; PrintElements(a, 10); void PrintElements(int * array, int size){ for (int i=0; i<size; i++) { cout << endl << array[i]; } } Now when I pr...

C++ convert string to hexadecimal and vice versa

What is the best way to convert a string to hex and vice versa in C++? Example: A string like "Hello World" to hex format: 48656C6C6F20576F726C64 And from hex 48656C6C6F20576F726C64 to string: "Hello World" ...

Microchip PIC C18 Programming File Format .COFF vs .HEX

I am developing code in the MPLAB IDE and I was wondering if it is better to program a chip using the .COFF or .HEX file generated by the compiler. I'm not sure what the difference is between the two and I am assuming they will both perform the same job. ...

Stripping hex bytes with sed - no match

I have a text file with two non-ascii bytes (0xFF and 0xFE): ??58832520.3,ABC 348384,DEF The hex for this file is: FF FE 35 38 38 33 32 35 32 30 2E 33 2C 41 42 43 0A 33 34 38 33 38 34 2C 44 45 46 It's coincidental that FF and FE happen to be the leading bytes (they exist throughout my file, although seemingly always at the beginnin...

Differences between 0x01 and 0x01f

I'm looking at the original source code for Identicons. There's a bit of code that does some bit twiddling to extract red, green and blue components: int blue = (code >> 16) & 0x01f; int green = (code >> 21) & 0x01f; int red = (code >> 27) & 0x01f; The code variable is a 32 bit integer. My question is this: What's the difference be...

XmlSerializer replaces spaces with 0x0020 (the hex value)

For some reason, my XmlElements with spaces in them are printed with _x0020 in place of the space. For example, [XmlElement("The Total")] public double total { get; set; } turns into <The_0x0020_Total> when I print it out. I'm using a TextWriter to output, then I use XmlSerializer.Serialize to print to a file, but it's not working. ...

Javascript parseInt with radix 16 issue

The alert statement alert(parseInt("0x00C02700010004E9",16)); incorrectly displays 54086076498707690 instead of the correct value 54086076498707689. Please notice the last two digits!! Could anyone shed some light on what am I doing wrong? ...

ZLIB Header Question

Hi, I would like to know how to determine how many zlib files are contained in a single file. An example; Think I have 5 different files, and compressed them separately by using zlib. Then I combined them. So, I have one file contains 5 different zlib files. Now, how can I find how many zlib files are in that single file? I just need t...

What is this encoding? Need to decode some strings. Unknown coding.

Hello, i need to decode some strings i found in some code i'm doing maintenance. What do you guys this is encoded to? How can I decode it? Thanks in advance. foo=97 8B 8B 8F C5 D0 D0 88 88 88 D1 96 92 9E 98 96 91 9E 8B 96 90 91 D1 9E 8B D0 99 93 9E 8D 9A D0 99 93 9E 8D 9A D1 8F 97 8F bar=10 9F 6B 37 02 DA B5 E9 18 3B E1 23 1B 61 ...

Placing a byte at a very specific address on a hard disk, can it be done? (using c++ for example)

This might sound silly, but I'd like to know how to do the following. I've created a .txt file. The content of the .txt file is the word "hi" without the quotes. So the .txt file contains 2 characters. When opening the .txt file in a hex-editor one sees 2 hexadecimal pairs, namely "68" and "69": Offset 00000000 68 69 hi What I want t...

Convert Hexadecimal MAC address to user readable formating (Python)

Hi, I'm receiving from the socket a MAC address in this format: 0024e865a023 (hex converted from binary with received-string.encode("hex")) I would like to convert it to a user readable format like this : 00-24-e8-65-a0-23 Any easy way to do so ? Thanks ...

How to get the binary presentation in hex value of a char

Given a char, how to convert this char to a two digit char, which is the hex value of the binary presentation? For example, given a char, it has a binary presentation, which is one byte, for example, 01010100, which is 0x54.....I need the char array of 54. ...