[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[IDV #PHU-486914]: question



Greetings Tilly,

Add this function to your local Jython library (click "Edit" -> "Formulas" -> 
"Jython Library", and select "Local Jython" -> "User's Library"), and give it a 
try:

def getBit(flag, n):
    """ 
    return the value of the nth bit of the given flag
    """
    bit_mask = 1 << (bitNumber -1)
    if ((bit_mask & flag) == 0):
        return 0
    else:
        return 1

(note: if the formatting of this function does not come out right in my 
message, be sure to add four spaces to everything after the first line [def 
getBit(flag, n):], and an additional four spaces to the "return" lines)

Cheers!

Sean


> Dear Sean
> Thank you for your help!
> I'm dealing with a 32 bit integer.
> Cheers,
> Tilly
> 
> -----Oorspronkelijk bericht-----
> Van: Unidata IDV Support [mailto:address@hidden]
> Verzonden: vrijdag 23 september 2011 18:59
> Aan: Driesenaar, Tilly (KNMI)
> Onderwerp: [IDV #PHU-486914]: question
> 
> Greetings Tilly!
> 
> What kind of interger is QCF (16 bit, 32 bit?)? In Jython 2.6, the bin 
> operator will be supported, so things will be much easier. However, you will 
> need to create a bitmask and use the bit-wise operator & to extract the 
> information you need. If I knew what kind of int you were dealing with, I 
> could give you an example to extract out the 17th bit.
> 
> Cheers!
> 
> Sean
> 
> > Dear IDV support desk
> >
> >
> >
> > I would like to plot the information in an integer quality flag in IDV.
> >
> > The flag consists of several masks, e.g. the first, or second or 17th
> > bit are set .
> >
> > In python I would use any of the following commands to extract
> > information from this integer quality flag (say QCF).
> >
> > (As you can see I'm especially interested in the 17th bit (or mask value
> > 2**17) )
> >
> >
> >
> > bin(int(QCF))[-18]  (look at the value of the 17th bit )
> >
> > or
> >
> > (int(QCF)/2**17)%2  (so divide by mask value and do modulo 2)
> >
> >
> >
> > How do I get this into an IDV formula?
> >
> > I tried (QCF/2**17)%2 , but that doesn't seem to evaluate in the right
> > way.
> >
> >
> >
> > Kind regards,
> >
> > Tilly Driesenaar
> >
> > KNMI
> >
> > The Netherlands
> >
> >
> >
> >
> >
> 
> 
> Ticket Details
> ===================
> Ticket ID: PHU-486914
> Department: Support IDV
> Priority: Normal
> Status: Closed
> 
> 


Ticket Details
===================
Ticket ID: PHU-486914
Department: Support IDV
Priority: Normal
Status: Open