Thanks in advance!
Thanks in advance!
EVERYTHING in a computer is stored as binary, so a char is binary already. I suspect what you are actually asking is how you DISPLAY a char as a binary value. To do that, you need to use modulo and divide to split the number into individual digits.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
Could you please give a simple example?because i'm a bit confused!Let's say we have 'w' and we wold like to get its value how do we use divide and modulo ?
Let's say we have the value 5.
5 Modulo 2 gives 1.
5 divide by 2 gives 2.
2 modulo 2 gives 0
2 divide by 2 gives 1
1 modulo 2 gives 1
1 divide by 2 gives 0.
The value of 5 in binary is therefore 101 (note that the numbers we get from the above calculation are "backwards", so you need to store the digits and display them from the back in some way).
For all intents and purpose, 'w' will be seen as a number by the computer (compiler) - if for example you do:you would get the numeric value of 'w' (most likely 119, but it does depend on what type of character representation your computer uses - most use something based on ASCII, where 'w' is 119, but there are other standards in existence).Code:printf("'w' is %d\n", 'w');
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
Thank you very much!It worked!