Re: [R] Converting binary number to in Two´s complement representation

2020-01-25 Thread Richard M. Heiberger
no, ## I don't see any system in AISMessageFrame tail(AISMessageFrame) ## MessgeCode ## 95 85E:BR0F0P00032jS2P00DE7P3A00h0 ## 96 1349B:3000rCtrn553aR@JHD2d4O ## 97 7933.883509997 ## 98 B

Re: [R] Converting binary number to in Two´s complement representation

2020-01-25 Thread Paul Bernal
Dear friend Richard, Were you able to obtain the latitude and longitude values with that script? Thank you so much brother, Paul El sáb., 25 de enero de 2020 4:03 p. m., Richard M. Heiberger < r...@temple.edu> escribió: > ## from2Comp uses base R functions only > from2Comp <- function(x, binDi

Re: [R] Converting binary number to in Two´s complement representation

2020-01-25 Thread Richard M. Heiberger
## from2Comp uses base R functions only from2Comp <- function(x, binDigits=8) { ## binDigits=8 means 8 significant digits plus a sign bit, thus nchar(x) == 9 tmp <- strtoi(x, base=2) Neg <- (tmp > (2^binDigits - 1)) tmp[Neg] <- tmp[Neg] - (2^(binDigits + 1)) tmp } from2Comp(substr(as.cha

Re: [R] Converting binary number to in Two´s complement representation

2020-01-24 Thread Paul Bernal
Thanks brother, I really appreciate your help. Have an awesome weekend! El vie., 24 de enero de 2020 5:39 p. m., Richard M. Heiberger < r...@temple.edu> escribió: > I don't have my computer with me, so I am commenting right now on the > visual impression of the email. > > The latitude shows 90,

Re: [R] Converting binary number to in Two´s complement representation

2020-01-24 Thread Richard M. Heiberger
I don't have my computer with me, so I am commenting right now on the visual impression of the email. The latitude shows 90, 88, ... 2, 89, ... The labels are lexicographically ordered -1, -10, -11,... The latitude binrep look in correct order, and the labels looks like binary in order. These th

Re: [R] Converting binary number to in Two´s complement representation

2020-01-24 Thread Paul Bernal
Dear friend Richard, Thank you for your interest in helping me through this challenge. As requested, I am providing the two lat and long frames you suggested, plus the one single column I am trying to decode: LatitudeFrame: > dput(LatitudeFrame) structure(list(Latitude = structure(c(90L, 88L, 87

Re: [R] Converting binary number to in Two´s complement representation

2020-01-24 Thread Richard M. Heiberger
now I am even more puzzled. please complete the following two data.frames and send it to the list. latDegrees lat2Comp -90 -89 ... -1 0 1 ... 89 90 lonDegrees lon2Comp -180 -179 ... -91 -90 -89 xxx

Re: [R] Converting binary number to in Two´s complement representation

2020-01-24 Thread Paul Bernal
Hi Richard, That was just an example, to show that, for that particular string of binary numbers, the code works as expected. That is absolutely no related to the dataset I provided. If I try the function on the dataset, I get values well over the latitude and longitude boundaries (which should ra

Re: [R] Converting binary number to in Two´s complement representation

2020-01-24 Thread Richard M. Heiberger
You show the example > fun("10110010") [1] -78 as satisfactory. Where in your posted data set do you find the input string "10110010"? Please post a set of relevant input strings, and the answers you want from them. The rest of the columns are not helpful for this specific exercise. On Fri, Ja

Re: [R] Converting binary number to in Two´s complement representation

2020-01-24 Thread Paul Bernal
Dear friend Rui, Hope you are doing great. Firstly, I want to thank you for your super valuable and kind support of always. As I mentioned in earlier e-mails, I am trying to decode AIS type messages, and the only ones I am having a real hard time with, is with latitude and longitude. I tried the

Re: [R] Converting binary number to in Two´s complement representation

2020-01-20 Thread Rui Barradas
Hello, The function I included converts signed binary numbers into their decimal representation. They are negative if a) they are multiples of 8 bits and b) the most significant bit is a "1". If not just convert to integer. As for a) above, I assume that you will have 8 bit numbers. And the

Re: [R] Converting binary number to in Two´s complement representation

2020-01-20 Thread Paul Bernal
Dear friend Rui, Hope you are doing great, thanks for your kind feedback. The challenge I currently have at hand is to decode AIS messages and obtain latitude and longitude values from those. So basically, I want to accomplish something like in the example below. I want to convert this binary num

Re: [R] Converting binary number to in Two´s complement representation

2020-01-20 Thread Rui Barradas
Sorry, missunderstood the problem. Here it goes: fun <- function(x){ res <- sapply(x, function(y){ if(nchar(y) %% 8 != 0 || substr(y, 1, 1) == "0"){ strtoi(y, base = 2) }else{ y <- unlist(strsplit(y, "")) -sum((y != "1")*2^((length(y) - 1):0)) - 1 } }) unname(r

Re: [R] Converting binary number to in Two´s complement representation

2020-01-20 Thread Rui Barradas
Hello, Is this what you want? x <- "10110010" strtoi(x, base = 2) #[1] 178 Hope this helps, Rui Barradas Às 16:31 de 16/01/20, Paul Bernal escreveu: Dear friends, How can I convert the following binary number in two´s complement representation in R? 10110010 Any help and/or guidance wil

[R] Converting binary number to in Two´s complement representation

2020-01-20 Thread Paul Bernal
Dear friends, How can I convert the following binary number in two´s complement representation in R? 10110010 Any help and/or guidance will be greatly appreciated, Best regards, Paul [[alternative HTML version deleted]] __ R-help@r-project.