Assignment Help in Turbo 7.0 Pascal - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Assignment Help in Turbo 7.0 Pascal

khumbo23khumbo23 Posts: 2Member
can anyone help me write code to convert decimal numbers into binary numbers, i know very well how to do soo manually, its how to put my words into my program i need help with, am usuming i use the MOD function.....whatever the case i need some help. Thanks inadvance!
email ad: [email protected]

Comments

  • GWS01GWS01 Posts: 10Member
    I'm not sure what tools you have in TP, but here's a couple of algorithms in Basic ..

    [code]
    sub Bin(x:int)
    ' converts integer to binary (allowing for negative values) ..
    def j:int
    def s:string
    j = x
    if (j < 0) then j = j + 2147483647 + 1

    do
    s = ltrim$(str$(j % 2)) + s
    j = j / 2
    until j = 0

    if (x < 0) then s = "1" + s
    return s
    endsub

    sub Dec(s:string)
    ' converts binary string to integer ..
    def i,result:int
    result = 0
    for i = 1 to len(s)
    if mid$(s,i,1) = "1" then result = result + 2 ^ (len(s) - i)
    next i

    return result
    endsub
    [/code]
  • _Atex__Atex_ Posts: 163Member
    : can anyone help me write code to convert decimal numbers into binary
    : numbers, i know very well how to do soo manually, its how to put my
    : words into my program i need help with, am usuming i use the MOD
    : function.....whatever the case i need some help. Thanks inadvance!
    : email ad: [email protected]
    :

    There are quite few conversion related posts on this forum ( mostly with code examples ), read on.
Sign In or Register to comment.