[R] hexadecimal to binary conversion

Charles C. Berry cberry at tajo.ucsd.edu
Mon Jan 21 19:25:40 CET 2008


On Mon, 21 Jan 2008, Gallego Liberman, Matias wrote:

> Hi
>
> I am looking for a function to convert an hexadecimal base input to a
> binary base output.
>
> May anybody help me?

Here are some pieces. Roll up your own function.

> hexdat <- replicate(10, paste(format.hexmode(sample(16,4)-1),collapse=''))
> bin <- apply(outer(0:15,3:0,function(x,y) x%/%(2^y)%%2),1,paste,collapse="")
> names(bin) <- format.hexmode( 0:15 )
> cbind( hexdat, sapply( strsplit(hexdat,'') , function(x) paste( bin[x], collapse='' ) ) )

HTH,

Chuck

>
>
>
> Thank you
>
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

Charles C. Berry                            (858) 534-2098
                                             Dept of Family/Preventive Medicine
E mailto:cberry at tajo.ucsd.edu	            UC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/  La Jolla, San Diego 92093-0901



More information about the R-help mailing list