Pages: [1]   Go Down
Author Topic: type conversions  (Read 795 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 87
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

How do i preform type conversions? for example converting an int to char?
Logged

London
Offline Offline
Faraday Member
**
Karma: 8
Posts: 6240
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

is done in  C by casting as follows:

int i = 64;
char c;

c = (char)i;   // (char) casts the variable i to a char


casting can have unexpected side affects because the value after the cast may not fit in the variable it is cast to. For example if the int i was equal to 256 before the cast, the char won't be equal to that after the cast because the maximum value for a char is 255.
« Last Edit: March 02, 2008, 10:02:47 am by mem » Logged

Pages: [1]   Go Up
Jump to: