Octal to hexadecimal conversion by scanning user input.
More...
#include <assert.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
|
long | octalToDecimal (long octalValue) |
| Convert octal number to decimal number.
|
|
char * | octalToHexadecimal (long octalValue) |
| Convert octal number to hexadecimal number dynamically allocated memory needs to be freed by the calling the function free.
|
|
static void | test () |
| Test function.
|
|
int | main () |
| Main function.
|
|
Octal to hexadecimal conversion by scanning user input.
The octalToHexadecimal function take the octal number as long return a string hexadecimal value after conversion
- Author
- Rachit Bhalla
◆ main()
Main function.
- Returns
- 0 on exit
61{
62
64
65
66 int octalValue;
67 printf("Enter an octal number: ");
68 scanf("%d", &octalValue);
69
70
72 printf("Equivalent hexadecimal number is: %s", hexadecimalValue);
73
74
75 free(hexadecimalValue);
76
77
78 return 0;
79}
#define free(ptr)
This macro replace the standard free function with free_dbg.
Definition malloc_dbg.h:26
char * octalToHexadecimal(long octalValue)
Convert octal number to hexadecimal number dynamically allocated memory needs to be freed by the call...
Definition octal_to_hexadecimal.c:38
static void test()
Test function.
Definition octal_to_hexadecimal.c:48
◆ octalToDecimal()
long octalToDecimal |
( |
long |
octalValue | ) |
|
Convert octal number to decimal number.
- Parameters
-
octalValue | is the octal number that needs to be converted |
- Returns
- a decimal number after conversion
20 {
21 long decimalValue = 0;
22 int i = 0;
23 while (octalValue) {
24
25 decimalValue += (long)(octalValue % 10) * pow(8, i++);
26
27 octalValue /= 10;
28 }
29 return decimalValue;
30}
◆ octalToHexadecimal()
char * octalToHexadecimal |
( |
long |
octalValue | ) |
|
Convert octal number to hexadecimal number dynamically allocated memory needs to be freed by the calling the function free.
- Parameters
-
octalValue | is the octal number that needs to be converted |
- Returns
- a hexadecimal value as a string after conversion
38 {
39 char *hexadecimalValue =
malloc(256 *
sizeof(
char));
41 return hexadecimalValue;
42}
#define malloc(bytes)
This macro replace the standard malloc function with malloc_dbg.
Definition malloc_dbg.h:18
long octalToDecimal(long octalValue)
Convert octal number to decimal number.
Definition octal_to_hexadecimal.c:20
◆ test()
static void test |
( |
void |
| ) |
|
|
static |
Test function.
- Returns
- void