|
C programming convertions...need immediate help!!!
|
View this Thread in Original format
| bluE_Neon |
hey there fellow TA's :) this is a question for the TA programmers that we have out there...
i have an assignment where i need to convert interger to 32-bit binary, a Fibonacci generator & HTML Color Converter..
the thing is i have no idea how to write the code to convert :( ill have a look also at some web-sites, maybe they have can help...in the mean time, would you guys help me out plz :)
btw...the convertions must be done in function format, not basic logic
thnx |
|
|
| infinity HiGH |
| quote: | Originally posted by Coup
piss off :p |
u showed him Coup:rolleyes: :rolleyes: :p |
|
|
| k.k.d. |
the first and the last can easilly be... um... used as one.. I mean, all you need is to write a base convertion algorithm, (10 -> 2 in first case, 10 -> 16 in the second case).. plus you need a color table for the second one.. basic.
as fibonaci sequence, it's umm.. a 5 line recursive method... huk huk :(
But since it's in C, you will prolly need extra 2-3 lines for variable declaration in the beggining of the method.. :))
moo? |
|
|
| bluE_Neon |
| oki i know wat you mean, but i need the code itself not explanation...im having a problem coding the convertions, thats wat i need :) |
|
|
| bluE_Neon |
| man i need the CODE in modularity format, not how to convert it manually :p |
|
|
| Durafei |
ok.. conversion to binary..
destination is an array which will contain the binary representation WITH leading zeroes.
void toBinary(int number, char*destination){
int cur=1;
int i;
for (i=0;i<32;i++){
if ((number&cur)!=0){
destination[31-i]=1;
}else {
destination[31-i]=0;
}
cur = cur<<1
}
destination[32]=0;
}
I think it works, didn't test though.. it's pretty fast, no divisions at all :) |
|
|
| bluE_Neon |
| thnx man :) wat about the fibonacci generator & html color converter??? |
|
|
| Durafei |
fibonacci..
int fibonacci(int n){
int a=1, b=1(or is it 2??), temp;
int i;
if (n==1) return 1;
if (n==2) return 1; //or is 2nd fibonacci number 2 ? i forget
for (i=3;i<=n;i++){
temp=a+b;
a=b;
b=temp;
}
return temp;
}
i dunno wtf is html color converter. |
|
|
| bluE_Neon |
| hey man, ill pm you so we can chat about this :) thx a lot! :) |
|
|
| k.k.d. |
| do you realise that if you keep on c&p-ing, you won't learn ? ;( |
|
|
|
|