I'm trying to convert the ASCII values of each letter, into Binary but I'm not sure how to grab the decimal values and convert them. Here's the code that prints out a word with their ASCII values to the right  #include &lt;stdio.h&gt; #include &lt;string.h&gt;   int main (void) {     char c[20];    printf("Enter a word: ");    scanf("%s",&amp;c);     int i;    char *str = c;    int length = strlen(str);     for (i = 0; i &lt; length; i++) {       printf("%c = %d \n", str[i] , str[i]);    }    return 0; }   Example output:  Enter a word: Program P = 80 r = 114 o = 111 g = 103 r = 114 a = 97 m = 109
32798
I can print with printf as a hex or octal number.  Is there a format tag to print as binary, or arbitrary base? I am running gcc. printf(&quot;%d %x %o\n&quot;, 10, 10, 10); //prints &quot;10 A 12\n&quot; print(&quot;%b\n&quot;, 10); // prints &quot;%b\n&quot;
19442
I can never remember how I do this because it comes up so infrequently for me. But in C or C++, what is the best way to read a character from standard input without waiting for a newline (press enter).  Also ideally it wouldn't echo the input character to the screen. I just want to capture keystrokes with out effecting the console screen.
12888
I'm trying to print types like off_t and size_t.  What is the correct placeholder for printf() that is portable?  Or is there a completely different way to print those variables?
2136
I am looking for a way to convert a long string (from a dump), that represents hex values into a byte array.  I couldn't have phrased it better than the person that posted .  But to keep it original, I'll phrase it my own way: suppose I have a string "00A0BF" that I would like interpreted as the  byte[] {0x00,0xA0,0xBf}   what should I do?  I am a Java novice and ended up using BigInteger and watching out for leading hex zeros. But I think it is ugly and I am sure I am missing something simple.
10266
I have embedded a Python interpreter in a C program.  Suppose the C program reads some bytes from a file into a char array and learns (somehow) that the bytes represent text with a certain encoding (e.g., ISO 8859-1, Windows-1252, or UTF-8).  How do I decode the contents of this char array into a Python string?  The Python string should in general be of type unicode—for instance, a 0x93 in Windows-1252 encoded input becomes a u'\u0201c'.  I have attempted to use PyString_Decode, but it always fails when there are non-ASCII characters in the string.  Here is an example that fails:  #include &lt;Python.h&gt; #include &lt;stdio.h&gt;  int main(int argc, char *argv[]) {      char c_string[] = { (char)0x93, 0 };      PyObject *py_string;       Py_Initialize();       py_string = PyString_Decode(c_string, 1, "windows_1252", "replace");      if (!py_string) {           PyErr_Print();           return 1;      }      return 0; }   The error message is UnicodeEncodeError: 'ascii' codec can't encode character u'\u201c' in position 0: ordinal not in range(128), which indicates that the ascii encoding is used even though we specify windows_1252 in the call to PyString_Decode.  The following code works around the problem by using PyString_FromString to create a Python string of the undecoded bytes, then calling its decode method:  #include &lt;Python.h&gt; #include &lt;stdio.h&gt;  int main(int argc, char *argv[]) {      char c_string[] = { (char)0x93, 0 };      PyObject *raw, *decoded;       Py_Initialize();       raw = PyString_FromString(c_string);      printf("Undecoded: ");      PyObject_Print(raw, stdout, 0);      printf("\n");      decoded = PyObject_CallMethod(raw, "decode", "s", "windows_1252");      Py_DECREF(raw);      printf("Decoded: ");      PyObject_Print(decoded, stdout, 0);      printf("\n");      return 0; }
13911
Possible Duplicate:          Here is a test case:   void foo(int i, int j) {    printf("%d %d", i, j); } ... test = 0; foo(test++, test);   I would expect to get a "0 1" output, but I get "0 0"  What gives??
26327
What is the easiest way to handle huge numbers in C? I need to store values in the Area 1000^900, or in more human readable form 10^2700. Does anybody know of an easy way to do that? Any help would really be appreciated!
5995
When displaying the value of a decimal currently with .ToString(), it's accurate to like 15 decimal places, and since I'm using it to represent dollars and cents, I only want the output to be 2 decimal places.   Do I use a variation of .ToString() for this?
32121
I want to get the ASCII value of characters in a string in C#.  If my string has the value "9quali52ty3", I want an array with the ASCII values of each of the 11 characters.  How can I get ASCII values in C#?
32361
I have some numbers of different length (like 1, 999, 76492, so on) and I want to convert them all to strings with a common length (for example, if the length is 6, then those strings will be: '000001', '000999', '076492').   In other words, I need to add correct amount of leading zeros to the number.  int n = 999; string str = some_function(n,6); //str = '000999'   Is there a function like this in C++?
24951
I wrote a function in C that converts a string to an integer and returns the integer. When I call the function I also want it to let me know if the string is not a valid number. In the past I returned -1 when this error occurred, because I didn't need to convert strings to negative numbers. But now I want it to convert strings to negative numbers, so what is the best way to report the error?  In case I wasn't clear about this: I don't want this function to report the error to the user, I want it to report the error to the code that called the function. ("Report" might be the wrong word to use...)  Here's the code:  s32 intval(const char *string) {     bool negative = false;     u32 current_char = 0;      if (string[0] == '-') {         negative = true;         current_char = 1;     }      s32 num = 0;     while (string[current_char]) {         if (string[current_char] &lt; '0' || string[current_char] &gt; '9') {             // Return an error here.. but how?         }          num *= 10;         num += string[current_char] - '0';         current_char++;     }      if (negative) {         num = -num;     }      return num; }
91467
Is there a way to convert a character to an integer in C?   For example, from '5' to 5?
6363
Is there a way to match some Unicode range exactly. Let's use the  as an example: U+400 to U+52f  The whole range of chars could be printed (from bash or zsh) with:   $ echo -e $(printf '\\U%x' $(seq 0x400 0x52f)) ЀЁЂЃЄЅІЇЈЉЊЋЌЍЎЏАБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдежзийклмнопрстуфхцчшщъыьэюяѐёђѓєѕіїјљњћќѝўџѠѡѢѣѤѥѦѧѨѩѪѫѬѭѮѯѰѱѲѳѴѵѶѷѸѹѺѻѼѽѾѿҀҁ҂҃҄҇ҊҋҌҍҎҏҐґҒғҔҕҖҗҘҙҚқҜҝҞҟҠҡҢңҤҥҦҧҨҩҪҫҬҭҮүҰұҲҳҴҵҶҷҸҹҺһҼҽҾҿӀӁӂӃӄӅӆӇӈӉӊӋӌӍӎӏӐӑӒӓӔӕӖӗӘәӚӛӜӝӞӟӠӡӢӣӤӥӦӧӨөӪӫӬӭӮӯӰӱӲӳӴӵӶӷӸӹӺӻӼӽӾӿԀԁԂԃԄԅԆԇԈԉԊԋԌԍԎԏԐԑԒԓԔԕԖԗԘԙԚԛԜԝԞԟԠԡԢԣԤԥԦԧԨԩԪԫԬԭԮԯ   $ a=$(zsh -c 'echo -e $(printf '\''\\U%x'\'' $(seq 0x400 0x52f))')     To filter some range of it, lets use 0x452 to 0x490, this is the expected output:  $ b=$(bash -c 'echo -e $(printf '\''\\U%x'\'' $(seq 0x452 0x490))') $ echo "$b" ђѓєѕіїјљњћќѝўџѠѡѢѣѤѥѦѧѨѩѪѫѬѭѮѯѰѱѲѳѴѵѶѷѸѹѺѻѼѽѾѿҀҁ҂҃҄҇ҊҋҌҍҎҏҐ $ echo "$b" | xxd 00000000: d192 d193 d194 d195 d196 d197 d198 d199  ................ 00000010: d19a d19b d19c d19d d19e d19f d1a0 d1a1  ................ 00000020: d1a2 d1a3 d1a4 d1a5 d1a6 d1a7 d1a8 d1a9  ................ 00000030: d1aa d1ab d1ac d1ad d1ae d1af d1b0 d1b1  ................ 00000040: d1b2 d1b3 d1b4 d1b5 d1b6 d1b7 d1b8 d1b9  ................ 00000050: d1ba d1bb d1bc d1bd d1be d1bf d280 d281  ................ 00000060: d282 d283 d284 d285 d286 d287 d288 d289  ................ 00000070: d28a d28b d28c d28d d28e d28f d290 0a    ...............     But it seems impossible to filter with sed. This doesn't work:  $ echo "$a" | sed 's/[^\x452-\x490]//g'   Nor this (the result match other characters (probably a collating issue)):  $ echo "$a" | sed $'s/[^\u452-\u490]//g' АБВГжзийклмнопрстуфхцчшщъыьэюяёђєѕіїјљњћќѝўџҋҍҏҐҗҙқҝҟҡңҥҧҩҫҭүұҳҵҷҹһҽҿӂӄӆӈӊӌӎӐӒӔӝӟӡӣӥӧөӫӭӯӱӳӵӹԅԇԉԋԍԏ   Not even this (same collating issue):  $ echo "$a" | sed 's/[^ђ-Ґ]//g'   This work with awk:  $ echo "$a" | awk '{gsub(/[^ђ-Ґ]/,"")}1'   But the only way to use an hex range is to use shell to convert hex to an unicode character  $ echo "$a" | awk $'{gsub(/[^\u452-\u490]/,"")}1'   or (two solutions):  $ c=$(bash -c 'printf "\u452-\u490"')  $ echo "$a" | awk '{gsub(/[^'"$c"']/,"")}1' $ echo $a | awk -v ra="[^$c]" '{gsub(ra,"")}1'   Questions:   Is there a way to do this with sed? Could awk do it in hex numbers without a higher shell. If possible, what is exactly the range matched by the collating sequence that sed use with sed 's/[^ђ-Ґ]//g'.   P.S.: I know that could be done in perl, thanks.
46742
Is there a library or a class/function that I can use to convert an integer to it's verbal representation?  Example input:     4,567,788`   Example output:     Four million, Five hundred sixty-seven thousand, seven hundred eighty-eight
41565
The printf function takes an argument type, such as %d or %i for a signed int. However, I don't see anything for a long value.
78486
For example, if I have a unicode string, I can encode it as an ASCII string like so:  &gt;&gt;&gt; u'\u003cfoo/\u003e'.encode('ascii') '&lt;foo/&gt;'   However, I have e.g. this ASCII string:  '\u003foo\u003e'   ... that I want to turn into the same ASCII string as in my first example above:  '&lt;foo/&gt;'
37193
What is the preferred way to remove spaces from a string in C++? I could loop through all the characters and build a new string, but is there a better way?