TranceAddict Forums (www.tranceaddict.com/forums)
- Chill Out Room
-- C programming convertions...need immediate help!!!
C programming convertions...need immediate help!!!
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
piss off 
| quote: |
| Originally posted by Coup piss off |
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?
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 
here is the algorithm...if i can do this in assembly surely u can do it in C!!
http://www.geocities.com/regia_me/decToBin.htm
man i need the CODE in modularity format, not how to convert it manually 
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 
thnx man
wat about the fibonacci generator & html color converter???
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.
hey man, ill pm you so we can chat about this
thx a lot! 
do you realise that if you keep on c&p-ing, you won't learn shit? ;(
no shit man! but im getting help from Durafei and he's making time to explain it to me man
once i'll understand this, i'll remember these code 
| quote: |
| Originally posted by 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 |
| quote: |
| Originally posted by Backlight Didn't they teach you to line up your {}?? |
| quote: |
| Originally posted by Durafei 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; } |
Dude, the fastest of the three? the iterative method posted earlier is O(N) and only uses additions. how can the last method be faster?
| quote: |
| Originally posted by Durafei Dude, the fastest of the three? the iterative method posted earlier is O(N) and only uses additions. how can the last method be faster? |
Re: C programming convertions...need immediate help!!!
| quote: |
| Originally posted by 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 |
Powered by: vBulletin
Copyright © 2000-2021, Jelsoft Enterprises Ltd.