Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
16-bit signed or unsigned int -> ASCII
//gcc 5.4.0 #include <stdio.h> #include <stdint.h> #include <stdbool.h> void convertToASCII(uint8_t* chars, uint8_t digits, int32_t num); int main(void) { uint16_t num = 38589; uint8_t chars[6]; printf("%c%c%c%c%c\n", chars[0], chars[1], chars[2], chars[3], chars[4]); convertToASCII(chars, 6, num); printf("%d\n", num); printf("%c%c%c%c%c%c\n", chars[0], chars[1], chars[2], chars[3], chars[4], chars[5]); return 0; } void convertToASCII(uint8_t* chars, uint8_t digits, int32_t num) { uint8_t STOP = 0; if (num < 0) { chars[0] = '-'; STOP = 1; } num = (uint32_t)abs(num); for ( ; digits > STOP; digits--) { chars[digits-1] = num % 10 + '0'; num /= 10; printf("at index %i, cars = %c\n", digits-1, chars[digits-1]); } }
run
|
edit
|
history
|
help
0
example of scanf and basic integer manipulation
HeapSort
Test2
709 lab 3.1
alphabet2 pyramid right
150109_RecursividadParImpar
string_ptr_to_fct_param
Spring 2017 Project 2 v.03
Palindromo
Practice Problem 7