extract_bit: Get the value of a particular bit in a byte

Description Usage Arguments Details Value Author(s) References See Also Examples

Description

In many MODIS products, the information for each pixel is stored in a byte, which represents numbers between 0 and 255. A byte is made up of 8 bits, and is a base 2 representation of the number. In the MODIS cloud product, each bit encodes information; see documentation of the MODIS cloud product in question.

Usage

1
  extract_bit(intval, bitnum)

Arguments

intval

An integer between 0 and 255

bitnum

The bit number to return, between 1 and 8

Details

This function takes a byte and extracts the bits. The bits are in whatever order they are in the byte. If reading in the reverse direction is needed, the user should use rev.

Value

bitval The value of the bit (0 or 1).

Author(s)

Nicholas J. Matzke matzke@berkeley.edu

References

Ackerman S, Frey R, Strabala K, Liu Y, Gumley L, Baum B and Menzel P (2010). "Discriminating clear-sky from cloud with MODIS algorithm theoretical basis document (MOD35)." MODIS Cloud Mask Team, Cooperative Institute for Meteorological Satellite Studies, University of Wisconsin - Madison. <URL: http://modis-atmos.gsfc.nasa.gov/_docs/MOD35_ATBD_Collection6.pdf>.

GoldsmithMatzkeDawson2013

See Also

byteint2bit

get_bitgrid_2bits

Examples

1
2
3
4
intval = 123
extract_bit(intval, bitnum=1)
extract_bit(intval, bitnum=2)
extract_bit(intval, bitnum=8)

Example output

Loading required package: date
Loading required package: sp
Loading required package: sfsmisc
Loading required package: raster
Loading required package: rgdal
rgdal: version: 1.5-18, (SVN revision 1082)
Geospatial Data Abstraction Library extensions to R successfully loaded
Loaded GDAL runtime: GDAL 3.0.4, released 2020/01/28
Path to GDAL shared files: /usr/share/gdal
GDAL binary built with GEOS: TRUE 
Loaded PROJ runtime: Rel. 6.3.1, February 10th, 2020, [PJ_VERSION: 631]
Path to PROJ shared files: /usr/share/proj
Linking to sp version:1.4-4
To mute warnings of possible GDAL/OSR exportToProj4() degradation,
use options("rgdal_show_exportToProj4_warnings"="none") before loading rgdal.
[1] 1
[1] 1
[1] 0

modiscloud documentation built on May 2, 2019, 5:16 a.m.