add_1: add_1 to a binary number

Description Usage Arguments Value Note Author(s) See Also Examples

View source: R/add_1.R

Description

j is a binary representation of a integer number. The add_1 function adds 1 to the binary number j. The input is j and the output is j+1 in binary representation.

Usage

1
add_1(j)

Arguments

j

a binary representation

Value

j+1 is returned in binary form

Note

This function requires the binary representation to be read in backwards!

E.g 1 in binary representation is 000001 2 in binary representation is 000010 3 in binary representation is 000011 4 in binary representation is 000100 5 in binary representation is 000101 6 in binary representation is 000110 However add_1(c(1,0,0,0,0,0)) = rev(000010)

Author(s)

Hannah Lennon

See Also

c(1, 0, 1, 0, 0, 0) is 5 backwards so the result is 6 = 000110 backwards

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
add_1(c(1, 0, 1, 0, 0, 0))


## The function is currently defined as
function (j)
{
    m <- length(j)
    if (!j[1])
        j[1] <- 1
    else {
        j[1] <- 0
        j[2:m] <- add_1(j[2:m])
    }
    return(j)
  }

hlennon/copulaIVTS documentation built on Dec. 20, 2021, 4:45 p.m.