I want to print reversed binary number of x
, but its first digit wouldn't come out.
For example, If I put
dbf(35)
results should be
110001
but it comes out as
10001
I think something must be wrong with the while
loop, but cannot figure out exactly what.
dbf<-function(x){
vec<-1:5
while(x%/%2!=0){
if(is.integer(x)==F){
x<-x%/%2
} else {
x<-x/2
}
vec<-append(vec, x%%2)
}
vec<-vec[-(1:5)]
cat(vec)
}