Learn R Programming

compositions (version 2.0-4)

binary: Treating binary and g-adic numbers

Description

Allows the access to individual digits in binary (and general g-adic) numbers.

Usage

binary(x,mb=max(maxBit(x,g)),g=2)
unbinary(x,g=2)
bit(x,b,g=2)                       
# S3 method for numeric
bit(x,b=0:maxBit(x,g),g=2)
# S3 method for character
bit(x,b=0:maxBit(x,g),g=2)
bit(x,b,g=2) <- value                      
# S3 method for numeric
bit(x,b=0:maxBit(x,g),g=2) <- value
# S3 method for character
bit(x,b=0:maxBit(x,g),g=2) <- value
maxBit(x,g=2)
# S3 method for numeric
maxBit(x,g=2)
# S3 method for character
maxBit(x,g=2)
bitCount(x,mb=max(maxBit(x,g)),g=2)
gsi.orSum(...,g=2)
whichBits(x,mb=max(maxBit(x,g)),g=2,values=c(TRUE))
binary2logical(x,mb=max(maxBit(x,g)),g=2,values=c(TRUE))

Value

binary

returns a standard binary (or g-adic) character representation of the number

unbinary

returns a binary (or g-adic) representation of the number

bit

returns the values of the requested bits. The values are returned as a logical vector for binary numbers an as numeric digit values for other g-adic numbers.

maxBit

returns the most significant bit represented in the number. This is the highest bit set in numeric numbers and the highest actually given character in a character representation.

bitCount

returns the g-adic crossfoot of the number. For a binary number this is the number of bits set

gsi.orSum

Only works for binary numbers and does a parallel or on each of the bits for a list of binary numbers.

whichBits

returns the indices of the bits acutally set (or more precisely of the bits with value in values)

binary2logical

returns the a true false vector of the bits acutally set (or more precisely of the bits with value in values)

Arguments

x

a number either represented a g-adic character string or as a integeral numeric value

b

the indicies of the bits to be processes. The least significant bit has index 0.

mb

maximal bit. The index of the most significant bit to be treated

g

the base of the g-adic representation. 2 corresponds to binary numbers, 8 to octal numbers, 16 to hexadecimal numbers. g is limited by 36.

value

a vector of bit values to be selected or setted.

values

a vector of bit values that should be considered as TRUE.

...

some binary numbers

Author

K.Gerald v.d. Boogaart http://www.stat.boogaart.de

Details

These routines are primerily intended to manipulate g-adic numbers for user interface purposes and condensed representation of information. They are not intended for a long number arithmetic.

See Also

outlierplot

Examples

Run this code
(x<-unbinary("10101010"))
(y<-binary(x))
bit(x,1:3)
bit(y,0:3)
maxBit(x)
maxBit(y)
whichBits(x)
whichBits(y)
binary2logical(y)
bit(x) 
bit(y) 
gsi.orSum(y,1)
bitCount(x)
bitCount(y)
bit(x,2)<-1
x
bit(y,2)<-1
y

Run the code above in your browser using DataLab