Computer Science Canada

base 10 to base 2

Author:  ssr [ Mon Feb 28, 2005 1:45 pm ]
Post subject:  base 10 to base 2

This is the program I made in class that converts base 10 number to base 2
try it lol

8) 8)
code:
var count : int := 0
var base_10 : int
var temp : int
put "Enter a number that's base 10."
get base_10
temp := base_10

loop
    count := count + 1
    base_10 := base_10 div 2
    exit when base_10 = 0
end loop
var base_2 : array 1 .. count of int
for ii : 1 .. count
    base_2 (ii) := temp mod 2
    temp := temp div 2
end for
put "The base 2 number is "..
for decreasing x : count .. 1
    put base_2 (x) ..
end for

Author:  Mazer [ Mon Feb 28, 2005 2:24 pm ]
Post subject: 

Would you like to know about the easier way to do that?

Author:  zylum [ Mon Feb 28, 2005 3:58 pm ]
Post subject: 

you mean:

code:
var base_10 : int
get base_10
put intstr (base_10, 0, 2)


Laughing

Author:  ssr [ Mon Feb 28, 2005 7:00 pm ]
Post subject: 

lolol
tnx guys
I never knew that eh?
Laughing Laughing

Author:  ssr [ Mon Feb 28, 2005 7:02 pm ]
Post subject: 

well u can say the first post is a explanation of how it was transfered
lol 8)

Author:  Flikerator [ Wed Mar 02, 2005 10:13 pm ]
Post subject: 

I don't get it, whats the math behind this? Like what is it for...Lolz

Author:  Carino [ Wed Mar 02, 2005 10:52 pm ]
Post subject: 

Just decimal to binary... has no real use really. Unless you like doing calculations in binary.

Author:  Andy [ Thu Mar 03, 2005 8:27 pm ]
Post subject: 

rofles... binary has tones of use... if u do alot of contest problems, you'll see alot of problems involving filling bins or disks... and binary is quite useful plus its the fundamentals behind computers.. how can any geek not love binary?

Author:  ssr [ Thu Mar 03, 2005 11:25 pm ]
Post subject: 

I agree
binary is very useful when doing programming or wanna know how a computer work
but not common in evryday life 8)

Author:  Jackywsz [ Wed Mar 09, 2005 8:40 pm ]
Post subject:  BASSES

Didn't we do that in class sirui? (sigh...)
so...how do u convert a base 2 to base 7 then? 8)

Author:  ssr [ Wed Mar 09, 2005 8:55 pm ]
Post subject: 

BOOHO look at the date first JaCKY!!
it was before we learnt it!!
Confused 8)

Author:  ssr [ Wed Mar 09, 2005 9:08 pm ]
Post subject: 

code:
var la:string
var base : int
get la
base:=strint (la,2)
put base

thats change from base 2 to base 10 I think .... Shocked Rolling Eyes

Author:  Jackywsz [ Thu Mar 10, 2005 1:08 pm ]
Post subject: 

ok exactly, so how can u convert a base 2 to a base 9 or any odd number basses then? Embarassed Rolling Eyes 8) 8)

Author:  person [ Thu Mar 10, 2005 3:56 pm ]
Post subject: 

to base 10 to base 9

code:

var base_10 : int
get base_10
put intstr (base_10, 0, 9)

Author:  ssr [ Thu Mar 10, 2005 6:33 pm ]
Post subject: 

Jackywsz wrote:
ok exactly, so how can u convert a base 2 to a base 9 or any odd number basses then? Embarassed Rolling Eyes 8) 8)

ok u want teh actual formula?
tsktsk
didnt listen in class did u?
Laughing
ok now
base 2 to base 8

code:

100101011
group them first by 3
[100][101][011]
then see 0*1 + 0* 2+ 0*4= 4 the first group is 4
same thing, the second one is 5, the thrid one is 3
thus, the number is 453
Rolling Eyes

Author:  ssr [ Thu Mar 10, 2005 7:07 pm ]
Post subject: 

for base 2 to base 16
same thing as above, except group by 4

for base 10 to 2 look at the code above
for base 10 to 8

divide by 8 and get the reminder reverse it
thats it

PAY ATTTENTION IN CLASS!
Test on monday Smile 8)


: