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 175 views
175 views asked Feb 9, 2023 by avibootz
1 answer 116 views
1 answer 90 views
1 answer 122 views
122 views asked Feb 10, 2023 by avibootz
3 answers 196 views
196 views asked Feb 9, 2023 by avibootz
1 answer 141 views
...