 Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki Blog Search Turing Chat Room Members
hELP! ALL CONVERSTIONS PROJECT....       Author Message
hexx Posted: Mon Dec 09, 2002 6:12 pm   Post subject: hELP! ALL CONVERSTIONS PROJECT....

help me.... i have stupid project to do.....

i finsihed decimal to all places.....

i need to do:

-binary to all bases
-Hex to all bases and
-Octal to all bases

--------------------------------------------------------------------------------------
plz fix this HEX > DECIMAL prog for me:
 code: var hd:string put "Enter number (hex) toconvert to decimal)" get hd var temp : string := ""     var m, t, c, final, final1 : int := 0     temp := hd     c := length (temp)     for i : 1 .. length (temp) - 1         c := c - 1         put "I LOOP ", i         put "C LOOP ", c         if temp (i) = "A" then             m := 10         elsif temp (i) = "B" then             m := 11         elsif temp (i) = "C" then             m := 12         elsif temp (i) = "D" then             m := 13         elsif temp (i) = "E" then             m := 14         elsif temp (i) = "F" then             m := 15         else             m := strint (temp (i))         end if         if c = 1 and temp (i + 1) = "A" then             final1 := 10         elsif c = 1 and temp (i + 1) = "B" then             final1 := 11         elsif c = 1 and temp (i + 1) = "C" then             final1 := 12         elsif c = 1 and temp (i + 1) = "D" then             final1 := 13         elsif c = 1 and temp (i + 1) = "E" then             final1 := 14         elsif c = 1 and temp (i + 1) = "F" then             final1 := 15         elsif c = 1 then             final1 := strint (temp (i))         end if         put "Number or letters replaced by? ", m         t := m * 16 ** c         put "Just multiploed m by 16 and squred by c loop.. ", t         final := final + t         if c = 1 then             final := final + final1         end if         put "MY FINAL LAST ", final1         put "FINAL: ", final     end for     put final    Dan  Posted: Mon Dec 09, 2002 6:43 pm   Post subject: hummm

well i dont know what you are sposted to do for this progject excltey but you can use a comand in turing to covert bases.

hex to dec
 code: var num: string := "FF" put strint(num, 16)

dec to hex
 code: var num: int := 10 put intstr(num,0, 16)

dec to binaery
 code: var num: int := 10 put intstr(num,0, 2)

the code for intstr is

intstr ( i : int [ , width : int [ , base : int ] ] ) : string

the code for strint is

strint ( s : string [ , base : int ] ) : int

P.S. some teachers dont like this method becuse they did not take the time to look at the strint and intstr fuctions. so they think this is a big progject.
Computer Science Canada Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more! hexx Posted: Mon Dec 09, 2002 11:55 pm   Post subject: (No subject)

lol is IT THAT EASY? man... if i knew.. that

but our teacher is amrking the code so i would apprecaite it someone could get me the LONG VERSION of this...

thnx! Tony  Posted: Tue Dec 10, 2002 12:14 am   Post subject: (No subject)

well tell your teacher that its a bad programming practice to reinvent the wheel as the functions are already there, build in and ready to use. It saves time (therefor money), are executed faster and more accuratly and with no bugs (or less then your function).

anyway, binary to decimal:

 code: var d : int := 128 var num : string := "00000010" var decimal : int := 0 for i : 1 .. 8     if num (i) = "1" then         decimal := decimal + d     end if     d := round (d / 2) end for put decimal

In other bases, you just replace d with base ** length(num) and replace /2 with /base

that gotta convert every base to decimal for you. Tony's programming blog. DWITE - a programming contest. Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First        Page 1 of 1  [ 4 Posts ]
 Jump to:  Select a forum  CompSci.ca ------------ - Network News - General Discussion     General Forums   -----------------   - Hello World   - Featured Poll   - Contests     Contest Forums   -----------------   - DWITE   - [FP] Contest 2006/2008   - [FP] 2005/2006 Archive   - [FP] 2004/2005 Archive   - Off Topic     Lounges   ---------   - User Lounge   - VIP Lounge     Programming -------------- - General Programming     General Programming Forums   --------------------------------   - Functional Programming   - Logical Programming   - C     C   --   - C Help   - C Tutorials   - C Submissions   - C++     C++   ----   - C++ Help   - C++ Tutorials   - C++ Submissions   - Java     Java   -----   - Java Help   - Java Tutorials   - Java Submissions   - Ruby     Ruby   -----   - Ruby Help   - Ruby Tutorials   - Ruby Submissions   - Turing     Turing   --------   - Turing Help   - Turing Tutorials   - Turing Submissions   - PHP     PHP   ----   - PHP Help   - PHP Tutorials   - PHP Submissions   - Python     Python   --------   - Python Help   - Python Tutorials   - Python Submissions   - Visual Basic and Other Basics     VB   ---   - Visual Basic Help   - Visual Basic Tutorials   - Visual Basic Submissions     Education ----------- - Student Life   Graphics and Design ----------------------- - Web Design     Web Design Forums   ---------------------   - (X)HTML Help   - (X)HTML Tutorials   - Flash MX Help   - Flash MX Tutorials   - Graphics     Graphics Forums   ------------------   - Photoshop Tutorials   - The Showroom   - 2D Graphics   - 3D Graphics     Teams ------ - dTeam Public

 Style: Appalachia blueSilver eMJay subAppalachia subBlue subCanvas subEmjay subGrey subSilver subVereor Search: