08-09-2009
> convert the Hexstring stored in a char* into hex and then prefixing it with "0x" and suffix it with ','
I'm not really sure what you're trying to accomplish with that. A C-string in hex format is *one* printable representation of a number. In the computer's storage there is no such thing as hex format, it's just bits and bytes.
So, without reading your code, the only sane thing regarding number conversion is to switch between representations. I would suggest something like this:
> snprintf(string, sizeof(string)-1, "%x", (unsigned int)n)
10 More Discussions You Might Find Interesting
1. Programming
Hi everyone!
I was wondering if anyone knows how to change hex code back into ascii.
when i process a form:
" / " turn to " %2F "
" @ " turns to " %40 "
" ' " turns to " %27 "
" ( " turns to " %28 "
" ) " turns to " %29 "
this is my code so far: order.txt
thanks,
primal
p.s.... (1 Reply)
Discussion started by: primal
1 Replies
2. Shell Programming and Scripting
Hi Experts,
I have a file called "hex" which contains info like below
How do i convert everything in this file to decimal value? Please advice. Thanks (4 Replies)
Discussion started by: aismann
4 Replies
3. UNIX for Dummies Questions & Answers
Hi,
I have a char buf,ch; and the buf is filled with the result from MySQL server which I get like this numbytes = recv(sock, buf, 1024, 0));I have the followingcode to display the results
printf("received %ld bytes:\n",numbytes);
for(c=0;c<numbytes;c++){
ch = (char)buf;
... (2 Replies)
Discussion started by: alikims
2 Replies
4. UNIX for Advanced & Expert Users
Hello. I'm working on a project that involves creating public/private keys server-side using openssl and using the public key in a Javascript application to encrypt sensitive data in form fields before transmission to the server. Using an SSL https server connection was not an option in this... (1 Reply)
Discussion started by: jhopper
1 Replies
5. Shell Programming and Scripting
I am trying to convert a txt file that includes one long string of data. The lines are separated with hex value 7C (for pipe).
I am trying to process this file using SQR (Peoplesoft) so I thought the easiest thing to do would be to replace the eol char with a CRLF in unix so I can just... (4 Replies)
Discussion started by: sfedak
4 Replies
6. Programming
I want it to ouput "abcd", but it dosen't.
1 #include<stdio.h>
2 int main()
3 {
4 printf("a\x62cd");
5 }
6
gcc alarm.c -o alarm
alarm.c: In function 'main':
alarm.c:4:9: warning: hex escape sequence out of range
It seems that the complier joint "cd" as part of... (8 Replies)
Discussion started by: vistastar
8 Replies
7. Programming
Hi,
Is there really a difference between these two, std::hex and ios::hex??
I stumbled upon reading a line, "std::ios::hex is a bitmask (8 on gcc) and works with setf(). std::hex is the operator". Is this true?
Thanks (0 Replies)
Discussion started by: royalibrahim
0 Replies
8. Shell Programming and Scripting
I am writing a bash script to do some parsing on a log and I am running into a problem when it comes to converting only certain sections of the file from hex to ascii or hex to decimal.
Data Example:
The hex values after Hardware and SW Version I need to convert from Hex to ASCII and the... (16 Replies)
Discussion started by: Shiftkey
16 Replies
9. Shell Programming and Scripting
Hi Guys,
writing a small shell script, i need to convert parts of a string to "Hex". The problem is that it is not the full string that needs to be converted.
I think it's best to show an example:
$astring = "xxxxxx ABC+10+##########+DEF xxxx"
This is only an example to show how the... (9 Replies)
Discussion started by: HansHansen
9 Replies
10. Shell Programming and Scripting
How to convert decimal value to hex and than take 1st digits as variable
sample data
84844294,5,6
51291736,2,3
84844294,5,6
51291736,2,3
i can use {printf "%x,%d\n",$1,$2} but than i want to filter base on 1st hex digit 1st recrd (1 Reply)
Discussion started by: before4
1 Replies
LEARN ABOUT OSX
asn1_string_print_ex
ASN1_STRING_print_ex(3) OpenSSL ASN1_STRING_print_ex(3)
NAME
ASN1_STRING_print_ex, ASN1_STRING_print_ex_fp - ASN1_STRING output routines.
SYNOPSIS
#include <openssl/asn1.h>
int ASN1_STRING_print_ex(BIO *out, ASN1_STRING *str, unsigned long flags);
int ASN1_STRING_print_ex_fp(FILE *fp, ASN1_STRING *str, unsigned long flags);
int ASN1_STRING_print(BIO *out, ASN1_STRING *str);
DESCRIPTION
These functions output an ASN1_STRING structure. ASN1_STRING is used to represent all the ASN1 string types.
ASN1_STRING_print_ex() outputs str to out, the format is determined by the options flags. ASN1_STRING_print_ex_fp() is identical except it
outputs to fp instead.
ASN1_STRING_print() prints str to out but using a different format to ASN1_STRING_print_ex(). It replaces unprintable characters (other
than CR, LF) with '.'.
NOTES
ASN1_STRING_print() is a legacy function which should be avoided in new applications.
Although there are a large number of options frequently ASN1_STRFLGS_RFC2253 is suitable, or on UTF8 terminals ASN1_STRFLGS_RFC2253 &
~ASN1_STRFLGS_ESC_MSB.
The complete set of supported options for flags is listed below.
Various characters can be escaped. If ASN1_STRFLGS_ESC_2253 is set the characters determined by RFC2253 are escaped. If
ASN1_STRFLGS_ESC_CTRL is set control characters are escaped. If ASN1_STRFLGS_ESC_MSB is set characters with the MSB set are escaped: this
option should not be used if the terminal correctly interprets UTF8 sequences.
Escaping takes several forms.
If the character being escaped is a 16 bit character then the form "UXXXX" is used using exactly four characters for the hex
representation. If it is 32 bits then "WXXXXXXXX" is used using eight characters of its hex representation. These forms will only be used
if UTF8 conversion is not set (see below).
Printable characters are normally escaped using the backslash '' character. If ASN1_STRFLGS_ESC_QUOTE is set then the whole string is
instead surrounded by double quote characters: this is arguably more readable than the backslash notation. Other characters use the "XX"
using exactly two characters of the hex representation.
If ASN1_STRFLGS_UTF8_CONVERT is set then characters are converted to UTF8 format first. If the terminal supports the display of UTF8
sequences then this option will correctly display multi byte characters.
If ASN1_STRFLGS_IGNORE_TYPE is set then the string type is not interpreted at all: everything is assumed to be one byte per character. This
is primarily for debugging purposes and can result in confusing output in multi character strings.
If ASN1_STRFLGS_SHOW_TYPE is set then the string type itself is printed out before its value (for example "BMPSTRING"), this actually uses
ASN1_tag2str().
The content of a string instead of being interpreted can be "dumped": this just outputs the value of the string using the form #XXXX using
hex format for each octet.
If ASN1_STRFLGS_DUMP_ALL is set then any type is dumped.
Normally non character string types (such as OCTET STRING) are assumed to be one byte per character, if ASN1_STRFLGS_DUMP_UNKNOWN is set
then they will be dumped instead.
When a type is dumped normally just the content octets are printed, if ASN1_STRFLGS_DUMP_DER is set then the complete encoding is dumped
instead (including tag and length octets).
ASN1_STRFLGS_RFC2253 includes all the flags required by RFC2253. It is equivalent to:
ASN1_STRFLGS_ESC_2253 | ASN1_STRFLGS_ESC_CTRL | ASN1_STRFLGS_ESC_MSB |
ASN1_STRFLGS_UTF8_CONVERT | ASN1_STRFLGS_DUMP_UNKNOWN ASN1_STRFLGS_DUMP_DER
SEE ALSO
X509_NAME_print_ex(3), ASN1_tag2str(3)
HISTORY
TBA
50 2013-03-05 ASN1_STRING_print_ex(3)