convert an array from decimal to binary

From: Zhifeng Yang <yangzf01_at_nyahnyahspammersnyahnyah>
Date: Tue Apr 23 2013 - 09:22:05 MDT

Hi all

Is there some function that can convert an array from decimal to binary? I
have tried the following code. However it can only be used for one digit at
one time. I want to convert one array to binary.

function dectobin(dec_num:integer)
local dq, cmd
begin
;---Double quote character
  dq = str_get_dq()

;---UNIX command that converts decimal to binary
  cmd = "echo " + dq + "ibase=10;obase=2;" + dq + dec_num + " | bc "

;---Execute UNIX command and return an integer
  return(toint(systemfunc(cmd)))
end

; Main code
;---Decimal number to convert
begin
  dec_num = 7
  bin_num = dectobin(dec_num)

  print("decimal number = " + dec_num)
  print("binary number = " + bin_num)
end
So do you have any other ideas on this?
Thank you
Bruce

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Tue Apr 23 09:22:19 2013

This archive was generated by hypermail 2.1.8 : Tue Apr 23 2013 - 12:54:13 MDT