# Re: convert a decimal to 32 bit unsigned binary

From: Dave Allured - NOAA Affiliate <dave.allured_at_nyahnyahspammersnyahnyah>
Date: Tue Feb 19 2013 - 09:54:31 MST

Xiaoyan,

Oops, my mistake. I thought that the digits of "36" meant day numbers 3
and 6. By coincidence, it really is the encoded value of the 3rd and 6th
bits, in other words 36 = 2^(3-1) + 2^(6-1). Sorry for the confusion.

Returning to your original question, use the NCL function "touint" to
convert other NCL data types (numbers and strings) to NCL 32-bit unsigned
binary. The following example converts "36" as an NCL string type to data
type "uint" which is NCL 32-bit unsigned binary. Is this what you are
looking for?

x = "36" ; NCL string type
y = touint (x)
print (y)

Output:
Variable: y
Type: uint
Total Size: 4 bytes
1 values
Number of Dimensions: 1
Dimensions and sizes: [1]
Coordinates:
(0) 36

http://www.ncl.ucar.edu/Document/Manuals/Ref_Manual/NclDataTypes.shtml

If this is not what you want, it might be helpful if you show us the
Fortran code that you mentioned, so that we can understand what data
structure you are trying to get.

--Dave

On Tue, Feb 19, 2013 at 7:26 AM, cheryl Ma <xiaoyancloud@gmail.com> wrote:

> Dave,
>
> in this case, "36" is a decimal number. It need be converted to a 32-bit
> binary number and then one can know which day having the observation, e.g.
> If there is observation on the 1st day of the month, then bit 1 would be
> set to true and if there is observation on the 2nd day of the month, then
> bit 2 would be set to true and so on.
>
> We can write a fortran code to convert a decimal number to a 32-bit binary
> number. My question is if there is a function in ncl to do this?
>
> Thanks,
> Xiaoyan
>
>
>
>
> On Mon, Feb 18, 2013 at 4:01 PM, Dave Allured - NOAA Affiliate <
> dave.allured@noaa.gov> wrote:
>
>> Xiaoyan,
>>
>> Be careful. In the example you show, "36" is NOT a decimal number. It
>> looks like it is really a list of two separate integers, 3 and 6.
>>
>> It is good that the example image showed the graphic mapping between
>> calendar days and bit positions, because the statement "Days of Month
>> Observed = 36" is badly constructed and very misleading. Maybe they should
>> have said "Days of Month Observed = 3 and 6".
>>
>> So, what do you really want to do? Maybe convert a LIST of calendar day
>> numbers 1 to 31, to a 32-bit unsigned integer, using bit position encoding
>> as shown in this example?
>>
>>
>> --Dave
>>
>> On Mon, Feb 18, 2013 at 8:57 AM, cheryl Ma <xiaoyancloud@gmail.com>wrote:
>>
>>> Dear all,
>>>
>>> Is there any function in NCL to convert a decimal number to a 32-bit
>>> unsigned binary? In an example shown below, 36 is a decimal, so its binary
>>> is 00100100000000000000000000000000.
>>>
>>> Thanks,
>>> Xiaoyan
>>>
>>> ==============================================
>>> [image: Figure 3: days of month flag interpretation.]
>>>
>>> _______________________________________________
>>> ncl-talk mailing list
>>> List instructions, subscriber options, unsubscribe:
>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>>
>>>
>>
>
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>

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

This archive was generated by hypermail 2.1.8 : Thu Feb 21 2013 - 11:26:43 MST