# Thread: Is there any function for converting a character to a binary value?

1. ## Is there any function for converting a character to a binary value?

2. 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

3. 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 ?

4. 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:
Code:
`printf("'w' is %d\n", 'w');`
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).

--
Mats

5. Thank you very much!It worked!