If you want to transform a number into another number (not number to string of characters), and you can do with a small range (0 to 1023 for implementations with 32-bit integers), you don’t need to add char*
to the solution
unsigned int_to_int(unsigned k) { if (k == 0) return 0; if (k == 1) return 1; /* optional */ return (k % 2) + 10 * int_to_int(k / 2); }
HalosGhost suggested to compact the code into a single line
unsigned int int_to_int(unsigned int k) { return (k == 0 || k == 1 ? k : ((k % 2) + 10 * int_to_int(k / 2))); }
Related Posts:
- Are the shift operators (<<, >>) arithmetic or logical in C?
- What is “2’s Complement”?
- Why prefer two’s complement over sign-and-magnitude for signed numbers?
- bad operand types for binary operator “&” java
- Why unsigned int 0xFFFFFFFF is equal to int -1?
- Reading a binary file with python
- What is the difference between signed and unsigned binary
- binary bomb lab phase 6
- How is overflow detected in two’s complement?
- Read and write to binary files in C?
- How to used the alphabet binary symbols
- What is the “biggest” negative number on a 4-bit machine?
- convert decimal numbers to excess-127 representations
- Is it possible to program in binary?
- The difference between n++ and ++n at the end of a while loop? (ANSI C)
- How many spaces for tab character(\t)?
- Working on code to calculate cosine with factorial sum
- warning: implicit declaration of function
- What exactly is the difference between “pass by reference” in C and in C++?
- What does “collect2: error: ld returned 1 exit status” mean?
- Binary Search Tree Implementation in C++ STL?
- Floating point exception (core dumped)
- Correct format specifier for double in printf
- Compiler Error “void value not ignored as it ought to be” in C programming [duplicate]
- Scanf/Printf double variable C
- How to convert a string to integer in C?
- What is the behavior of integer division?
- max value of integer
- Convert an int to ASCII character
- Awesomium sdk download
- Error “initializer element is not constant” when trying to initialize variable with const
- Cannot assign requested address – possible causes?
- need help understanding the movzbl call in this function
- How to extract C source code from .so file?
- What is the difference between read and pread in unix?
- What does “control reaches end of non-void function” mean?
- connect Error: “No route to host”
- C error: undefined reference to function, but it IS defined
- What is the printf format specifier for bool?
- warning: implicit declaration of function
- How to printf “unsigned long” in C?
- Why do I get an assertion failure?
- Difference between int32, int, int32_t, int8 and int8_t
- What does \x00 mean in binary file?
- lvalue required as left operand of assignment
- how to convert negative hexadecimal to decimal
- Why am I getting “undefined reference to sqrt” error even though I inclu de math.h header?
- How to initialize a struct in accordance with C programming language standards
- Expression preceding parentheses?
- Linux equivalent of I_PUSH
- Understanding INADDR_ANY for socket programming
- expression must have integral type
- Why is %c used in C?
- How to convert string to binary?
- What is Innermost loop in imperfectly nested loops?
- What’s wrong with my code? What is argv[1]?
- What can cause a “Resource temporarily unavailable” on sock send() command
- How to get the current directory in a C program?
- What’s the best way to check if a file exists in C?
- How to solve error: expected identifier or ‘(‘
- C compile : collect2: error: ld returned 1 exit status
- Split string with delimiters in C
- Why am I getting this error: “data definition has no type or storage class”?
- I’m getting “Invalid Initializer”, what am I doing wrong?
- Warning/error “function declaration isn’t a prototype”
- Error: initializer element is not computable at load time
- %i or %d to print integer in C using printf()?
- How can I get the list of files in a directory using C or C++?
- How to prevent multiple definitions in C?
- How can you print multiple variables inside a string using printf?
- Multi-character constant warnings
- warning: passing argument ’from incompatible pointer type [enabled by default]’
- Return a `struct` from a function in C
- C dynamically growing array
- Why should we check WIFEXITED after wait in order to kill child processes in Linux system call?
- How to convert const char* to char* in C?
- Scanning Multiple inputs from one line using scanf
- C subscripted value is neither array nor pointer nor vector when assigning an array element value
- error: too few arguments to function `printDay’ (C language)
- Implementing a HashMap in C
- How to parse in C
- error: unknown type name ‘bool’
- Optional arguments in C function
- Which of sprintf/snprintf is more secure?
- Where is the
header file on Linux? Why can’t I find ? - Converting integer to binary in python
- Python conversion from binary string to hexadecimal
- Why is the sizeof(int) == sizeof(long)?
- Passing string to a function in C – with or without pointers?
- Using ‘printf’ on a variable in C [closed]
- “warning: useless storage class specifier in empty declaration” in struct
- How to allocate array of pointers for strings by malloc in C?
- Why are there no hashtables in the C standard library?
- Reasoning behind C sockets sockaddr and sockaddr_storage
- Use of flag in c?
- Reading float using scanf in c
- “-bash: gcc: command not found” using cygwin when compiling c?
- What do \t and \b do?
- write() to stdout and printf output not interleaved?
- How to use random() in C [duplicate]