C++ help

Abbysmall

New member
Trusted Member
Apr 19, 2012
46
0
so i kinda have to make in C++ a program that convert Decimal values to binary values...
I belived it was easy but im trying to do the damn thing for 5 hours now and i realized i aint that smart...
please if someone out there know how to do this accursed program please give me a help,
i tried google but i found a lot of ways that i didnt understand...
i would like to use the "binary(int)" but i dont know what library is needed to binary(int) to work, if someone could please explain to me how to use it i would be very pleased... helping or not, trying to help or not i thank you for taking your time to read this i appreciate it! and whoever( or whatever i dont know wich is right to use here) you belive in bless us all.
PS: if you believe in nothing thats ok i hope you have a great day!
i use iostream ya know cout <<, cin >> and stuff.
 
I'm not familiar with C++, but it looks like you are trying to access a binary method that you would either need a library for, or more likely that you are supposed to write yourself.
I think you could make something that does this in not too long by using for loops (keep counting up the number and adding to your binary number).
 
yeah i will have to use repetitions for sure, but it must only work for numbers between 0~255 , but i tried many times using while or for and yet something was wrong, i will try to understand the bitset thing to use in the program thanks guys
 
[MENTION=25932]ClaudioFGX[/MENTION] ; I don't know much about C++ as that is not my language major :P

But I know the mathematics concept to convert decimal to binary.

Okay as you already know, decimal is a base 10 system and binary is base 2. So in order to convert decimal to binary within the maximum value binary will support: 255, you take your decimal number and divide it by 2.

Example: 200 will be written as "200base10" (I don't know how to make the special symbols pop up), and you will take that number and divide it in long division by 2, (because that is the base count for binary.)

Now for every quotient that is even, you write a "0" and for every quotient that is odd, you write a "1". You just keep dividing until your quotient is 0.

Example 2: 200 converted to binary is:

200/2 = 100 that is a 0
100/2 = 50 that is a 0
50/2 = 25 that is a 0
25/2 = 12 that is a 1
13/2 = 6 that is a 0
6/2 = 3 that is a 0
3/2 = 1 that is a 1
1/2 = 0 that is a 1

So 200 in binary = 11001000

Hope this is what you were looking for.
 

Users who are viewing this thread