How to convert unsigned short to char in C

2 Answers

0 votes
#include <stdio.h> 

int main(void) 
{ 
	unsigned short s = 100;
	char ch = (char)s;
	
	printf("%c\n", ch);
	
    return 0; 
} 
  
  
  
/*
run:
  
d
 
*/

 



answered Aug 8, 2019 by avibootz
0 votes
#include <stdio.h> 

int main(void) 
{ 
	unsigned short s = 0xAF;
	char ch = (char)s;
	
	printf("%c\n", ch);
	
    return 0; 
} 
  
  
  
/*
run:
  
»

*/

 



answered Aug 8, 2019 by avibootz

Related questions

3 answers 180 views
180 views asked Feb 9, 2023 by avibootz
1 answer 120 views
1 answer 94 views
1 answer 126 views
126 views asked Feb 10, 2023 by avibootz
3 answers 200 views
200 views asked Feb 9, 2023 by avibootz
1 answer 144 views
...