|
google site
|
|||||||
| Forums | Register | Blog | Man Pages | Forum Rules | Links | Albums | FAQ | Users | Calendar | Search | Today's Posts | Mark Forums Read |
| Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
![]() |
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hexadecimal to ascii
Let's suppose i have a hexadecimal array with 16 cells.for example
b3e2d5f636111780 i want to convert it to an array of ascii characters(in C) so that i can reduce total size of the file i want to put it in. But i am afraid i have not fully understand the difference between ascii and hex(i thought that an ascii array is simply a char* array but this seems wrong). Thank you in advance. ![]() |
| Sponsored Links | ||
|
|
|
#2
|
||||
|
||||
|
Ascii characters are made up from one 8 bit byte. So a "|" (pipe symbol) is represented by a value of 179 decimal, or b3 hexadecimal.
What you have in your original string is 16 8-bit bytes. If you take these in pairs and multiply the first by 16 and add the second, you will end up with a value between 0 and 255, (b *16 +3 = 11 * 16 +3 = 179), which you can then store in a single 8 bit byte, resulting in a 50% reduction in storage. |
|
#3
|
|||
|
|||
|
Quote:
|
|
#4
|
|||
|
|||
|
There are a few more things to consider. First, strings with an odd number of characters must be flagged somehow so that the resulting representation can be converted back into an odd number of characters. Second, you're turning a string into the native representation of an integer. So, you need to decide which endianness the storage will have if you want the resulting file to be compatible across architectures.
|
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Test Hexadecimal number | francis_tom | Shell Programming and Scripting | 2 | 09-23-2009 06:17 PM |
| convert ascii values into ascii characters | sandeeppvk | Shell Programming and Scripting | 10 | 04-23-2009 11:23 PM |
| Hexadecimal to Decimal | Arunprasad | UNIX for Dummies Questions & Answers | 2 | 02-25-2009 03:30 AM |
| looping in hexadecimal with bash | soba | UNIX for Dummies Questions & Answers | 2 | 07-01-2008 12:36 PM |
| Get Hexadecimal Value | lesstjm | Shell Programming and Scripting | 2 | 09-07-2005 09:29 AM |