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

Paul Bernal p@u|bern@|07 @end|ng |rom gm@||@com
Fri Jan 24 23:47:01 CET 2020


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 <
rmh using 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, 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 things are identified as factors, not as character.
>
> Please ensure that character values are not misinterpreted as factor when
> you construct your data frames.
>
> The four columns do not look to be in consistent order with each other.
> This in itself could cause trouble.
>
> I will look more when I have my computer running R so I can follow the
> rest of what you wrote.
>
> Rich
>
> On Fri, Jan 24, 2020 at 15:02 Paul Bernal <paulbernal07 using gmail.com> wrote:
>
>> 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, 87L, 86L, 85L,
>> 84L, 83L, 82L, 81L, 80L, 79L, 77L, 76L, 75L, 74L, 73L, 72L, 71L,
>> 70L, 69L, 68L, 66L, 65L, 64L, 63L, 62L, 61L, 60L, 59L, 58L, 57L,
>> 55L, 54L, 53L, 52L, 51L, 50L, 49L, 48L, 47L, 46L, 44L, 43L, 42L,
>> 41L, 40L, 39L, 38L, 37L, 36L, 35L, 33L, 32L, 31L, 30L, 29L, 28L,
>> 27L, 26L, 25L, 24L, 22L, 21L, 20L, 19L, 18L, 17L, 16L, 15L, 14L,
>> 13L, 11L, 10L, 9L, 8L, 7L, 6L, 5L, 4L, 3L, 2L, 89L, 78L, 67L,
>> 56L, 45L, 34L, 23L, 12L, 1L, 91L, 92L, 103L, 114L, 125L, 136L,
>> 147L, 158L, 169L, 180L, 93L, 94L, 95L, 96L, 97L, 98L, 99L, 100L,
>> 101L, 102L, 104L, 105L, 106L, 107L, 108L, 109L, 110L, 111L, 112L,
>> 113L, 115L, 116L, 117L, 118L, 119L, 120L, 121L, 122L, 123L, 124L,
>> 126L, 127L, 128L, 129L, 130L, 131L, 132L, 133L, 134L, 135L, 137L,
>> 138L, 139L, 140L, 141L, 142L, 143L, 144L, 145L, 146L, 148L, 149L,
>> 150L, 151L, 152L, 153L, 154L, 155L, 156L, 157L, 159L, 160L, 161L,
>> 162L, 163L, 164L, 165L, 166L, 167L, 168L, 170L, 171L, 172L, 173L,
>> 174L, 175L, 176L, 177L, 178L, 179L, 181L), .Label = c("-1", "-10",
>> "-11", "-12", "-13", "-14", "-15", "-16", "-17", "-18", "-19",
>> "-2", "-20", "-21", "-22", "-23", "-24", "-25", "-26", "-27",
>> "-28", "-29", "-3", "-30", "-31", "-32", "-33", "-34", "-35",
>> "-36", "-37", "-38", "-39", "-4", "-40", "-41", "-42", "-43",
>> "-44", "-45", "-46", "-47", "-48", "-49", "-5", "-50", "-51",
>> "-52", "-53", "-54", "-55", "-56", "-57", "-58", "-59", "-6",
>> "-60", "-61", "-62", "-63", "-64", "-65", "-66", "-67", "-68",
>> "-69", "-7", "-70", "-71", "-72", "-73", "-74", "-75", "-76",
>> "-77", "-78", "-79", "-8", "-80", "-81", "-82", "-83", "-84",
>> "-85", "-86", "-87", "-88", "-89", "-9", "-90", "0", "1", "10",
>> "11", "12", "13", "14", "15", "16", "17", "18", "19", "2", "20",
>> "21", "22", "23", "24", "25", "26", "27", "28", "29", "3", "30",
>> "31", "32", "33", "34", "35", "36", "37", "38", "39", "4", "40",
>> "41", "42", "43", "44", "45", "46", "47", "48", "49", "5", "50",
>> "51", "52", "53", "54", "55", "56", "57", "58", "59", "6", "60",
>> "61", "62", "63", "64", "65", "66", "67", "68", "69", "7", "70",
>> "71", "72", "73", "74", "75", "76", "77", "78", "79", "8", "80",
>> "81", "82", "83", "84", "85", "86", "87", "88", "89", "9", "90"
>> ), class = "factor"), LatitudeBinRep = structure(c(92L, 93L,
>> 94L, 95L, 96L, 97L, 98L, 99L, 100L, 101L, 102L, 103L, 104L, 105L,
>> 106L, 107L, 108L, 109L, 110L, 111L, 112L, 113L, 114L, 115L, 116L,
>> 117L, 118L, 119L, 120L, 121L, 122L, 123L, 124L, 125L, 126L, 127L,
>> 128L, 129L, 130L, 131L, 132L, 133L, 134L, 135L, 136L, 137L, 138L,
>> 139L, 140L, 141L, 142L, 143L, 144L, 145L, 146L, 147L, 148L, 149L,
>> 150L, 151L, 152L, 153L, 154L, 155L, 156L, 157L, 158L, 159L, 160L,
>> 161L, 162L, 163L, 164L, 165L, 166L, 167L, 168L, 169L, 170L, 171L,
>> 172L, 173L, 174L, 175L, 176L, 177L, 178L, 179L, 180L, 181L, 1L,
>> 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L,
>> 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L,
>> 29L, 30L, 31L, 32L, 33L, 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L,
>> 42L, 43L, 44L, 45L, 46L, 47L, 48L, 49L, 50L, 51L, 52L, 53L, 54L,
>> 55L, 56L, 57L, 58L, 59L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L,
>> 68L, 69L, 70L, 71L, 72L, 73L, 74L, 75L, 76L, 77L, 78L, 79L, 80L,
>> 81L, 82L, 83L, 84L, 85L, 86L, 87L, 88L, 89L, 90L, 91L), .Label =
>> c("0000000000000000000000000000000",
>> "0000000000000000000000000000001", "0000000000000000000000000000010",
>> "0000000000000000000000000000011", "0000000000000000000000000000100",
>> "0000000000000000000000000000101", "0000000000000000000000000000110",
>> "0000000000000000000000000000111", "0000000000000000000000000001000",
>> "0000000000000000000000000001001", "0000000000000000000000000001010",
>> "0000000000000000000000000001011", "0000000000000000000000000001100",
>> "0000000000000000000000000001101", "0000000000000000000000000001110",
>> "0000000000000000000000000001111", "0000000000000000000000000010000",
>> "0000000000000000000000000010001", "0000000000000000000000000010010",
>> "0000000000000000000000000010011", "0000000000000000000000000010100",
>> "0000000000000000000000000010101", "0000000000000000000000000010110",
>> "0000000000000000000000000010111", "0000000000000000000000000011000",
>> "0000000000000000000000000011001", "0000000000000000000000000011010",
>> "0000000000000000000000000011011", "0000000000000000000000000011100",
>> "0000000000000000000000000011101", "0000000000000000000000000011110",
>> "0000000000000000000000000011111", "0000000000000000000000000100000",
>> "0000000000000000000000000100001", "0000000000000000000000000100010",
>> "0000000000000000000000000100011", "0000000000000000000000000100100",
>> "0000000000000000000000000100101", "0000000000000000000000000100110",
>> "0000000000000000000000000100111", "0000000000000000000000000101000",
>> "0000000000000000000000000101001", "0000000000000000000000000101010",
>> "0000000000000000000000000101011", "0000000000000000000000000101100",
>> "0000000000000000000000000101101", "0000000000000000000000000101110",
>> "0000000000000000000000000101111", "0000000000000000000000000110000",
>> "0000000000000000000000000110001", "0000000000000000000000000110010",
>> "0000000000000000000000000110011", "0000000000000000000000000110100",
>> "0000000000000000000000000110101", "0000000000000000000000000110110",
>> "0000000000000000000000000110111", "0000000000000000000000000111000",
>> "0000000000000000000000000111001", "0000000000000000000000000111010",
>> "0000000000000000000000000111011", "0000000000000000000000000111100",
>> "0000000000000000000000000111101", "0000000000000000000000000111110",
>> "0000000000000000000000000111111", "0000000000000000000000001000000",
>> "0000000000000000000000001000001", "0000000000000000000000001000010",
>> "0000000000000000000000001000011", "0000000000000000000000001000100",
>> "0000000000000000000000001000101", "0000000000000000000000001000110",
>> "0000000000000000000000001000111", "0000000000000000000000001001000",
>> "0000000000000000000000001001001", "0000000000000000000000001001010",
>> "0000000000000000000000001001011", "0000000000000000000000001001100",
>> "0000000000000000000000001001101", "0000000000000000000000001001110",
>> "0000000000000000000000001001111", "0000000000000000000000001010000",
>> "0000000000000000000000001010001", "0000000000000000000000001010010",
>> "0000000000000000000000001010011", "0000000000000000000000001010100",
>> "0000000000000000000000001010101", "0000000000000000000000001010110",
>> "0000000000000000000000001010111", "0000000000000000000000001011000",
>> "0000000000000000000000001011001", "0000000000000000000000001011010",
>> "1111111111111111111111110100110", "1111111111111111111111110100111",
>> "1111111111111111111111110101000", "1111111111111111111111110101001",
>> "1111111111111111111111110101010", "1111111111111111111111110101011",
>> "1111111111111111111111110101100", "1111111111111111111111110101101",
>> "1111111111111111111111110101110", "1111111111111111111111110101111",
>> "1111111111111111111111110110000", "1111111111111111111111110110001",
>> "1111111111111111111111110110010", "1111111111111111111111110110011",
>> "1111111111111111111111110110100", "1111111111111111111111110110101",
>> "1111111111111111111111110110110", "1111111111111111111111110110111",
>> "1111111111111111111111110111000", "1111111111111111111111110111001",
>> "1111111111111111111111110111010", "1111111111111111111111110111011",
>> "1111111111111111111111110111100", "1111111111111111111111110111101",
>> "1111111111111111111111110111110", "1111111111111111111111110111111",
>> "1111111111111111111111111000000", "1111111111111111111111111000001",
>> "1111111111111111111111111000010", "1111111111111111111111111000011",
>> "1111111111111111111111111000100", "1111111111111111111111111000101",
>> "1111111111111111111111111000110", "1111111111111111111111111000111",
>> "1111111111111111111111111001000", "1111111111111111111111111001001",
>> "1111111111111111111111111001010", "1111111111111111111111111001011",
>> "1111111111111111111111111001100", "1111111111111111111111111001101",
>> "1111111111111111111111111001110", "1111111111111111111111111001111",
>> "1111111111111111111111111010000", "1111111111111111111111111010001",
>> "1111111111111111111111111010010", "1111111111111111111111111010011",
>> "1111111111111111111111111010100", "1111111111111111111111111010101",
>> "1111111111111111111111111010110", "1111111111111111111111111010111",
>> "1111111111111111111111111011000", "1111111111111111111111111011001",
>> "1111111111111111111111111011010", "1111111111111111111111111011011",
>> "1111111111111111111111111011100", "1111111111111111111111111011101",
>> "1111111111111111111111111011110", "1111111111111111111111111011111",
>> "1111111111111111111111111100000", "1111111111111111111111111100001",
>> "1111111111111111111111111100010", "1111111111111111111111111100011",
>> "1111111111111111111111111100100", "1111111111111111111111111100101",
>> "1111111111111111111111111100110", "1111111111111111111111111100111",
>> "1111111111111111111111111101000", "1111111111111111111111111101001",
>> "1111111111111111111111111101010", "1111111111111111111111111101011",
>> "1111111111111111111111111101100", "1111111111111111111111111101101",
>> "1111111111111111111111111101110", "1111111111111111111111111101111",
>> "1111111111111111111111111110000", "1111111111111111111111111110001",
>> "1111111111111111111111111110010", "1111111111111111111111111110011",
>> "1111111111111111111111111110100", "1111111111111111111111111110101",
>> "1111111111111111111111111110110", "1111111111111111111111111110111",
>> "1111111111111111111111111111000", "1111111111111111111111111111001",
>> "1111111111111111111111111111010", "1111111111111111111111111111011",
>> "1111111111111111111111111111100", "1111111111111111111111111111101",
>> "1111111111111111111111111111110", "1111111111111111111111111111111"
>> ), class = "factor")), class = "data.frame", row.names = c(NA,
>> -181L))
>>
>> LongitudeFrame:
>>
>> > dput(LongitudeFrame)
>> structure(list(Longitude = structure(c(91L, 89L, 88L, 87L, 86L,
>> 85L, 84L, 83L, 82L, 81L, 80L, 78L, 77L, 76L, 75L, 74L, 73L, 72L,
>> 71L, 70L, 69L, 67L, 66L, 65L, 64L, 63L, 62L, 61L, 60L, 59L, 58L,
>> 56L, 55L, 54L, 53L, 52L, 51L, 50L, 49L, 48L, 47L, 45L, 44L, 43L,
>> 42L, 41L, 40L, 39L, 38L, 37L, 36L, 34L, 33L, 32L, 31L, 30L, 29L,
>> 28L, 27L, 26L, 25L, 23L, 22L, 21L, 20L, 19L, 18L, 17L, 16L, 15L,
>> 14L, 12L, 11L, 10L, 9L, 8L, 7L, 6L, 5L, 4L, 3L, 180L, 179L, 178L,
>> 177L, 176L, 175L, 174L, 173L, 172L, 171L, 169L, 168L, 167L, 166L,
>> 165L, 164L, 163L, 162L, 161L, 160L, 158L, 157L, 156L, 155L, 154L,
>> 153L, 152L, 151L, 150L, 149L, 147L, 146L, 145L, 144L, 143L, 142L,
>> 141L, 140L, 139L, 138L, 136L, 135L, 134L, 133L, 132L, 131L, 130L,
>> 129L, 128L, 127L, 125L, 124L, 123L, 122L, 121L, 120L, 119L, 118L,
>> 117L, 116L, 114L, 113L, 112L, 111L, 110L, 109L, 108L, 107L, 106L,
>> 105L, 103L, 102L, 101L, 100L, 99L, 98L, 97L, 96L, 95L, 94L, 92L,
>> 90L, 79L, 68L, 57L, 46L, 35L, 24L, 13L, 2L, 170L, 159L, 148L,
>> 137L, 126L, 115L, 104L, 93L, 1L, 181L, 182L, 274L, 285L, 296L,
>> 307L, 318L, 329L, 340L, 351L, 183L, 194L, 205L, 216L, 227L, 238L,
>> 249L, 260L, 271L, 273L, 275L, 276L, 277L, 278L, 279L, 280L, 281L,
>> 282L, 283L, 284L, 286L, 287L, 288L, 289L, 290L, 291L, 292L, 293L,
>> 294L, 295L, 297L, 298L, 299L, 300L, 301L, 302L, 303L, 304L, 305L,
>> 306L, 308L, 309L, 310L, 311L, 312L, 313L, 314L, 315L, 316L, 317L,
>> 319L, 320L, 321L, 322L, 323L, 324L, 325L, 326L, 327L, 328L, 330L,
>> 331L, 332L, 333L, 334L, 335L, 336L, 337L, 338L, 339L, 341L, 342L,
>> 343L, 344L, 345L, 346L, 347L, 348L, 349L, 350L, 352L, 353L, 354L,
>> 355L, 356L, 357L, 358L, 359L, 360L, 361L, 184L, 185L, 186L, 187L,
>> 188L, 189L, 190L, 191L, 192L, 193L, 195L, 196L, 197L, 198L, 199L,
>> 200L, 201L, 202L, 203L, 204L, 206L, 207L, 208L, 209L, 210L, 211L,
>> 212L, 213L, 214L, 215L, 217L, 218L, 219L, 220L, 221L, 222L, 223L,
>> 224L, 225L, 226L, 228L, 229L, 230L, 231L, 232L, 233L, 234L, 235L,
>> 236L, 237L, 239L, 240L, 241L, 242L, 243L, 244L, 245L, 246L, 247L,
>> 248L, 250L, 251L, 252L, 253L, 254L, 255L, 256L, 257L, 258L, 259L,
>> 261L, 262L, 263L, 264L, 265L, 266L, 267L, 268L, 269L, 270L, 272L
>> ), .Label = c("-1", "-10", "-100", "-101", "-102", "-103", "-104",
>> "-105", "-106", "-107", "-108", "-109", "-11", "-110", "-111",
>> "-112", "-113", "-114", "-115", "-116", "-117", "-118", "-119",
>> "-12", "-120", "-121", "-122", "-123", "-124", "-125", "-126",
>> "-127", "-128", "-129", "-13", "-130", "-131", "-132", "-133",
>> "-134", "-135", "-136", "-137", "-138", "-139", "-14", "-140",
>> "-141", "-142", "-143", "-144", "-145", "-146", "-147", "-148",
>> "-149", "-15", "-150", "-151", "-152", "-153", "-154", "-155",
>> "-156", "-157", "-158", "-159", "-16", "-160", "-161", "-162",
>> "-163", "-164", "-165", "-166", "-167", "-168", "-169", "-17",
>> "-170", "-171", "-172", "-173", "-174", "-175", "-176", "-177",
>> "-178", "-179", "-18", "-180", "-19", "-2", "-20", "-21", "-22",
>> "-23", "-24", "-25", "-26", "-27", "-28", "-29", "-3", "-30",
>> "-31", "-32", "-33", "-34", "-35", "-36", "-37", "-38", "-39",
>> "-4", "-40", "-41", "-42", "-43", "-44", "-45", "-46", "-47",
>> "-48", "-49", "-5", "-50", "-51", "-52", "-53", "-54", "-55",
>> "-56", "-57", "-58", "-59", "-6", "-60", "-61", "-62", "-63",
>> "-64", "-65", "-66", "-67", "-68", "-69", "-7", "-70", "-71",
>> "-72", "-73", "-74", "-75", "-76", "-77", "-78", "-79", "-8",
>> "-80", "-81", "-82", "-83", "-84", "-85", "-86", "-87", "-88",
>> "-89", "-9", "-90", "-91", "-92", "-93", "-94", "-95", "-96",
>> "-97", "-98", "-99", "0", "1", "10", "100", "101", "102", "103",
>> "104", "105", "106", "107", "108", "109", "11", "110", "111",
>> "112", "113", "114", "115", "116", "117", "118", "119", "12",
>> "120", "121", "122", "123", "124", "125", "126", "127", "128",
>> "129", "13", "130", "131", "132", "133", "134", "135", "136",
>> "137", "138", "139", "14", "140", "141", "142", "143", "144",
>> "145", "146", "147", "148", "149", "15", "150", "151", "152",
>> "153", "154", "155", "156", "157", "158", "159", "16", "160",
>> "161", "162", "163", "164", "165", "166", "167", "168", "169",
>> "17", "170", "171", "172", "173", "174", "175", "176", "177",
>> "178", "179", "18", "180", "19", "2", "20", "21", "22", "23",
>> "24", "25", "26", "27", "28", "29", "3", "30", "31", "32", "33",
>> "34", "35", "36", "37", "38", "39", "4", "40", "41", "42", "43",
>> "44", "45", "46", "47", "48", "49", "5", "50", "51", "52", "53",
>> "54", "55", "56", "57", "58", "59", "6", "60", "61", "62", "63",
>> "64", "65", "66", "67", "68", "69", "7", "70", "71", "72", "73",
>> "74", "75", "76", "77", "78", "79", "8", "80", "81", "82", "83",
>> "84", "85", "86", "87", "88", "89", "9", "90", "91", "92", "93",
>> "94", "95", "96", "97", "98", "99"), class = "factor"), LongitudeBinRep =
>> structure(c(182L,
>> 183L, 184L, 185L, 186L, 187L, 188L, 189L, 190L, 191L, 192L, 193L,
>> 194L, 195L, 196L, 197L, 198L, 199L, 200L, 201L, 202L, 203L, 204L,
>> 205L, 206L, 207L, 208L, 209L, 210L, 211L, 212L, 213L, 214L, 215L,
>> 216L, 217L, 218L, 219L, 220L, 221L, 222L, 223L, 224L, 225L, 226L,
>> 227L, 228L, 229L, 230L, 231L, 232L, 233L, 234L, 235L, 236L, 237L,
>> 238L, 239L, 240L, 241L, 242L, 243L, 244L, 245L, 246L, 247L, 248L,
>> 249L, 250L, 251L, 252L, 253L, 254L, 255L, 256L, 257L, 258L, 259L,
>> 260L, 261L, 262L, 263L, 264L, 265L, 266L, 267L, 268L, 269L, 270L,
>> 271L, 272L, 273L, 274L, 275L, 276L, 277L, 278L, 279L, 280L, 281L,
>> 282L, 283L, 284L, 285L, 286L, 287L, 288L, 289L, 290L, 291L, 292L,
>> 293L, 294L, 295L, 296L, 297L, 298L, 299L, 300L, 301L, 302L, 303L,
>> 304L, 305L, 306L, 307L, 308L, 309L, 310L, 311L, 312L, 313L, 314L,
>> 315L, 316L, 317L, 318L, 319L, 320L, 321L, 322L, 323L, 324L, 325L,
>> 326L, 327L, 328L, 329L, 330L, 331L, 332L, 333L, 334L, 335L, 336L,
>> 337L, 338L, 339L, 340L, 341L, 342L, 343L, 344L, 345L, 346L, 347L,
>> 348L, 349L, 350L, 351L, 352L, 353L, 354L, 355L, 356L, 357L, 358L,
>> 359L, 360L, 361L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L,
>> 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L,
>> 25L, 26L, 27L, 28L, 29L, 30L, 31L, 32L, 33L, 34L, 35L, 36L, 37L,
>> 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L, 47L, 48L, 49L, 50L,
>> 51L, 52L, 53L, 54L, 55L, 56L, 57L, 58L, 59L, 60L, 61L, 62L, 63L,
>> 64L, 65L, 66L, 67L, 68L, 69L, 70L, 71L, 72L, 73L, 74L, 75L, 76L,
>> 77L, 78L, 79L, 80L, 81L, 82L, 83L, 84L, 85L, 86L, 87L, 88L, 89L,
>> 90L, 91L, 92L, 93L, 94L, 95L, 96L, 97L, 98L, 99L, 100L, 101L,
>> 102L, 103L, 104L, 105L, 106L, 107L, 108L, 109L, 110L, 111L, 112L,
>> 113L, 114L, 115L, 116L, 117L, 118L, 119L, 120L, 121L, 122L, 123L,
>> 124L, 125L, 126L, 127L, 128L, 129L, 130L, 131L, 132L, 133L, 134L,
>> 135L, 136L, 137L, 138L, 139L, 140L, 141L, 142L, 143L, 144L, 145L,
>> 146L, 147L, 148L, 149L, 150L, 151L, 152L, 153L, 154L, 155L, 156L,
>> 157L, 158L, 159L, 160L, 161L, 162L, 163L, 164L, 165L, 166L, 167L,
>> 168L, 169L, 170L, 171L, 172L, 173L, 174L, 175L, 176L, 177L, 178L,
>> 179L, 180L, 181L), .Label = c("0000000000000000000000000000000",
>> "0000000000000000000000000000001", "0000000000000000000000000000010",
>> "0000000000000000000000000000011", "0000000000000000000000000000100",
>> "0000000000000000000000000000101", "0000000000000000000000000000110",
>> "0000000000000000000000000000111", "0000000000000000000000000001000",
>> "0000000000000000000000000001001", "0000000000000000000000000001010",
>> "0000000000000000000000000001011", "0000000000000000000000000001100",
>> "0000000000000000000000000001101", "0000000000000000000000000001110",
>> "0000000000000000000000000001111", "0000000000000000000000000010000",
>> "0000000000000000000000000010001", "0000000000000000000000000010010",
>> "0000000000000000000000000010011", "0000000000000000000000000010100",
>> "0000000000000000000000000010101", "0000000000000000000000000010110",
>> "0000000000000000000000000010111", "0000000000000000000000000011000",
>> "0000000000000000000000000011001", "0000000000000000000000000011010",
>> "0000000000000000000000000011011", "0000000000000000000000000011100",
>> "0000000000000000000000000011101", "0000000000000000000000000011110",
>> "0000000000000000000000000011111", "0000000000000000000000000100000",
>> "0000000000000000000000000100001", "0000000000000000000000000100010",
>> "0000000000000000000000000100011", "0000000000000000000000000100100",
>> "0000000000000000000000000100101", "0000000000000000000000000100110",
>> "0000000000000000000000000100111", "0000000000000000000000000101000",
>> "0000000000000000000000000101001", "0000000000000000000000000101010",
>> "0000000000000000000000000101011", "0000000000000000000000000101100",
>> "0000000000000000000000000101101", "0000000000000000000000000101110",
>> "0000000000000000000000000101111", "0000000000000000000000000110000",
>> "0000000000000000000000000110001", "0000000000000000000000000110010",
>> "0000000000000000000000000110011", "0000000000000000000000000110100",
>> "0000000000000000000000000110101", "0000000000000000000000000110110",
>> "0000000000000000000000000110111", "0000000000000000000000000111000",
>> "0000000000000000000000000111001", "0000000000000000000000000111010",
>> "0000000000000000000000000111011", "0000000000000000000000000111100",
>> "0000000000000000000000000111101", "0000000000000000000000000111110",
>> "0000000000000000000000000111111", "0000000000000000000000001000000",
>> "0000000000000000000000001000001", "0000000000000000000000001000010",
>> "0000000000000000000000001000011", "0000000000000000000000001000100",
>> "0000000000000000000000001000101", "0000000000000000000000001000110",
>> "0000000000000000000000001000111", "0000000000000000000000001001000",
>> "0000000000000000000000001001001", "0000000000000000000000001001010",
>> "0000000000000000000000001001011", "0000000000000000000000001001100",
>> "0000000000000000000000001001101", "0000000000000000000000001001110",
>> "0000000000000000000000001001111", "0000000000000000000000001010000",
>> "0000000000000000000000001010001", "0000000000000000000000001010010",
>> "0000000000000000000000001010011", "0000000000000000000000001010100",
>> "0000000000000000000000001010101", "0000000000000000000000001010110",
>> "0000000000000000000000001010111", "0000000000000000000000001011000",
>> "0000000000000000000000001011001", "0000000000000000000000001011010",
>> "0000000000000000000000001011011", "0000000000000000000000001011100",
>> "0000000000000000000000001011101", "0000000000000000000000001011110",
>> "0000000000000000000000001011111", "0000000000000000000000001100000",
>> "0000000000000000000000001100001", "0000000000000000000000001100010",
>> "0000000000000000000000001100011", "0000000000000000000000001100100",
>> "0000000000000000000000001100101", "0000000000000000000000001100110",
>> "0000000000000000000000001100111", "0000000000000000000000001101000",
>> "0000000000000000000000001101001", "0000000000000000000000001101010",
>> "0000000000000000000000001101011", "0000000000000000000000001101100",
>> "0000000000000000000000001101101", "0000000000000000000000001101110",
>> "0000000000000000000000001101111", "0000000000000000000000001110000",
>> "0000000000000000000000001110001", "0000000000000000000000001110010",
>> "0000000000000000000000001110011", "0000000000000000000000001110100",
>> "0000000000000000000000001110101", "0000000000000000000000001110110",
>> "0000000000000000000000001110111", "0000000000000000000000001111000",
>> "0000000000000000000000001111001", "0000000000000000000000001111010",
>> "0000000000000000000000001111011", "0000000000000000000000001111100",
>> "0000000000000000000000001111101", "0000000000000000000000001111110",
>> "0000000000000000000000001111111", "0000000000000000000000010000000",
>> "0000000000000000000000010000001", "0000000000000000000000010000010",
>> "0000000000000000000000010000011", "0000000000000000000000010000100",
>> "0000000000000000000000010000101", "0000000000000000000000010000110",
>> "0000000000000000000000010000111", "0000000000000000000000010001000",
>> "0000000000000000000000010001001", "0000000000000000000000010001010",
>> "0000000000000000000000010001011", "0000000000000000000000010001100",
>> "0000000000000000000000010001101", "0000000000000000000000010001110",
>> "0000000000000000000000010001111", "0000000000000000000000010010000",
>> "0000000000000000000000010010001", "0000000000000000000000010010010",
>> "0000000000000000000000010010011", "0000000000000000000000010010100",
>> "0000000000000000000000010010101", "0000000000000000000000010010110",
>> "0000000000000000000000010010111", "0000000000000000000000010011000",
>> "0000000000000000000000010011001", "0000000000000000000000010011010",
>> "0000000000000000000000010011011", "0000000000000000000000010011100",
>> "0000000000000000000000010011101", "0000000000000000000000010011110",
>> "0000000000000000000000010011111", "0000000000000000000000010100000",
>> "0000000000000000000000010100001", "0000000000000000000000010100010",
>> "0000000000000000000000010100011", "0000000000000000000000010100100",
>> "0000000000000000000000010100101", "0000000000000000000000010100110",
>> "0000000000000000000000010100111", "0000000000000000000000010101000",
>> "0000000000000000000000010101001", "0000000000000000000000010101010",
>> "0000000000000000000000010101011", "0000000000000000000000010101100",
>> "0000000000000000000000010101101", "0000000000000000000000010101110",
>> "0000000000000000000000010101111", "0000000000000000000000010110000",
>> "0000000000000000000000010110001", "0000000000000000000000010110010",
>> "0000000000000000000000010110011", "0000000000000000000000010110100",
>> "1111111111111111111111101001100", "1111111111111111111111101001101",
>> "1111111111111111111111101001110", "1111111111111111111111101001111",
>> "1111111111111111111111101010000", "1111111111111111111111101010001",
>> "1111111111111111111111101010010", "1111111111111111111111101010011",
>> "1111111111111111111111101010100", "1111111111111111111111101010101",
>> "1111111111111111111111101010110", "1111111111111111111111101010111",
>> "1111111111111111111111101011000", "1111111111111111111111101011001",
>> "1111111111111111111111101011010", "1111111111111111111111101011011",
>> "1111111111111111111111101011100", "1111111111111111111111101011101",
>> "1111111111111111111111101011110", "1111111111111111111111101011111",
>> "1111111111111111111111101100000", "1111111111111111111111101100001",
>> "1111111111111111111111101100010", "1111111111111111111111101100011",
>> "1111111111111111111111101100100", "1111111111111111111111101100101",
>> "1111111111111111111111101100110", "1111111111111111111111101100111",
>> "1111111111111111111111101101000", "1111111111111111111111101101001",
>> "1111111111111111111111101101010", "1111111111111111111111101101011",
>> "1111111111111111111111101101100", "1111111111111111111111101101101",
>> "1111111111111111111111101101110", "1111111111111111111111101101111",
>> "1111111111111111111111101110000", "1111111111111111111111101110001",
>> "1111111111111111111111101110010", "1111111111111111111111101110011",
>> "1111111111111111111111101110100", "1111111111111111111111101110101",
>> "1111111111111111111111101110110", "1111111111111111111111101110111",
>> "1111111111111111111111101111000", "1111111111111111111111101111001",
>> "1111111111111111111111101111010", "1111111111111111111111101111011",
>> "1111111111111111111111101111100", "1111111111111111111111101111101",
>> "1111111111111111111111101111110", "1111111111111111111111101111111",
>> "1111111111111111111111110000000", "1111111111111111111111110000001",
>> "1111111111111111111111110000010", "1111111111111111111111110000011",
>> "1111111111111111111111110000100", "1111111111111111111111110000101",
>> "1111111111111111111111110000110", "1111111111111111111111110000111",
>> "1111111111111111111111110001000", "1111111111111111111111110001001",
>> "1111111111111111111111110001010", "1111111111111111111111110001011",
>> "1111111111111111111111110001100", "1111111111111111111111110001101",
>> "1111111111111111111111110001110", "1111111111111111111111110001111",
>> "1111111111111111111111110010000", "1111111111111111111111110010001",
>> "1111111111111111111111110010010", "1111111111111111111111110010011",
>> "1111111111111111111111110010100", "1111111111111111111111110010101",
>> "1111111111111111111111110010110", "1111111111111111111111110010111",
>> "1111111111111111111111110011000", "1111111111111111111111110011001",
>> "1111111111111111111111110011010", "1111111111111111111111110011011",
>> "1111111111111111111111110011100", "1111111111111111111111110011101",
>> "1111111111111111111111110011110", "1111111111111111111111110011111",
>> "1111111111111111111111110100000", "1111111111111111111111110100001",
>> "1111111111111111111111110100010", "1111111111111111111111110100011",
>> "1111111111111111111111110100100", "1111111111111111111111110100101",
>> "1111111111111111111111110100110", "1111111111111111111111110100111",
>> "1111111111111111111111110101000", "1111111111111111111111110101001",
>> "1111111111111111111111110101010", "1111111111111111111111110101011",
>> "1111111111111111111111110101100", "1111111111111111111111110101101",
>> "1111111111111111111111110101110", "1111111111111111111111110101111",
>> "1111111111111111111111110110000", "1111111111111111111111110110001",
>> "1111111111111111111111110110010", "1111111111111111111111110110011",
>> "1111111111111111111111110110100", "1111111111111111111111110110101",
>> "1111111111111111111111110110110", "1111111111111111111111110110111",
>> "1111111111111111111111110111000", "1111111111111111111111110111001",
>> "1111111111111111111111110111010", "1111111111111111111111110111011",
>> "1111111111111111111111110111100", "1111111111111111111111110111101",
>> "1111111111111111111111110111110", "1111111111111111111111110111111",
>> "1111111111111111111111111000000", "1111111111111111111111111000001",
>> "1111111111111111111111111000010", "1111111111111111111111111000011",
>> "1111111111111111111111111000100", "1111111111111111111111111000101",
>> "1111111111111111111111111000110", "1111111111111111111111111000111",
>> "1111111111111111111111111001000", "1111111111111111111111111001001",
>> "1111111111111111111111111001010", "1111111111111111111111111001011",
>> "1111111111111111111111111001100", "1111111111111111111111111001101",
>> "1111111111111111111111111001110", "1111111111111111111111111001111",
>> "1111111111111111111111111010000", "1111111111111111111111111010001",
>> "1111111111111111111111111010010", "1111111111111111111111111010011",
>> "1111111111111111111111111010100", "1111111111111111111111111010101",
>> "1111111111111111111111111010110", "1111111111111111111111111010111",
>> "1111111111111111111111111011000", "1111111111111111111111111011001",
>> "1111111111111111111111111011010", "1111111111111111111111111011011",
>> "1111111111111111111111111011100", "1111111111111111111111111011101",
>> "1111111111111111111111111011110", "1111111111111111111111111011111",
>> "1111111111111111111111111100000", "1111111111111111111111111100001",
>> "1111111111111111111111111100010", "1111111111111111111111111100011",
>> "1111111111111111111111111100100", "1111111111111111111111111100101",
>> "1111111111111111111111111100110", "1111111111111111111111111100111",
>> "1111111111111111111111111101000", "1111111111111111111111111101001",
>> "1111111111111111111111111101010", "1111111111111111111111111101011",
>> "1111111111111111111111111101100", "1111111111111111111111111101101",
>> "1111111111111111111111111101110", "1111111111111111111111111101111",
>> "1111111111111111111111111110000", "1111111111111111111111111110001",
>> "1111111111111111111111111110010", "1111111111111111111111111110011",
>> "1111111111111111111111111110100", "1111111111111111111111111110101",
>> "1111111111111111111111111110110", "1111111111111111111111111110111",
>> "1111111111111111111111111111000", "1111111111111111111111111111001",
>> "1111111111111111111111111111010", "1111111111111111111111111111011",
>> "1111111111111111111111111111100", "1111111111111111111111111111101",
>> "1111111111111111111111111111110", "1111111111111111111111111111111"
>> ), class = "factor")), class = "data.frame", row.names = c(NA,
>> -361L))
>>
>> AISMessageFrame (Raw Messages as they come from the AIS device):
>>
>> > dput(AISMessageFrame)
>> structure(list(MessgeCode = structure(c(17L, 6L, 93L, 92L, 81L,
>> 24L, 4L, 44L, 21L, 43L, 66L, 64L, 94L, 46L, 26L, 82L, 12L, 9L,
>> 67L, 63L, 65L, 39L, 48L, 38L, 79L, 83L, 37L, 73L, 23L, 68L, 59L,
>> NA, 5L, 30L, 62L, 84L, 60L, 22L, 52L, 61L, 50L, 70L, 96L, 85L,
>> 33L, 51L, 8L, 16L, 19L, 71L, 76L, 86L, 34L, 25L, 14L, 53L, 10L,
>> 29L, 2L, 77L, 57L, 87L, 72L, 54L, 55L, 36L, 1L, 13L, NA, 78L,
>> 58L, 15L, 89L, 35L, 20L, 3L, 49L, 56L, 90L, 40L, 45L, 41L, 42L,
>> 74L, 95L, 32L, 91L, 27L, 69L, 76L, 18L, 31L, 11L, 80L, 75L, 7L,
>> 72L, 88L, 28L, 47L), .Label = c("1:u0KOh001rCq5P529qqubqh2 using 3n",
>> "100000?P00JCkt:583J=r?v:283Q", "10007NgP00rCQGV5:Pa=?gv>2<1H",
>> "1000Fo using P01rCuG<56bnkN?v004`0", "1018lEWP?w<tSF0l4Q@>4?wp0W3h",
>> "1349B:3000rCtrn553aR using JH02PRp", "1349B:3000rCtrn553aR using JHD2d4O",
>> "137g`F8007rCaIj59Tc5Dl using 800SN", "139NL4000LrCc8j59FEED4 using 000S<",
>> "13M using Hk00jSJD@RD4s=qG1mT80 using 3J", "13P;K8 using 001rCfgr58=f;QbFD2D4G",
>> "13P;K8 using Oh1rCfgp58=ec1bD22<4J", "13P>4mhw1CrCi5H57aK5WlN>0<4F",
>> "14aMBf000wrCKKN5:sdU0Sv<083C", "14S8 using n001LrD?bH53iGe1rN>0 using 49",
>> "15?7P`0P00rD1S453KSlj?v824`0", "15?f5H?P00rCQat5:Oah0?wn2 using S6",
>> "15?lSL?P00JCQWD5:OpP0?vB24`0", "15?mqH?P00rCek458rkEN?v:00S4",
>> "15 using EA<0P01JCo8l53=BFgwv using 0D47", "15 using eD@8000rC`bl59kW`mFn004`0",
>> "15>nNj0000rCT<@5::qUpkt604`0", "15>uP00P00rC`U:59im;H?v22 using 1D",
>> "15A using av3P00rClHn53<I8M?v02<2B", "15AIw`0P0GrCcO859DO5Ogv:0T`0",
>> "15Aq00?P00rC`a`59mFeogv004`0", "15ATk20000rCnrv53N6;gPr>085R",
>> "15B3Sj0000rC9RD5=mOh40jB20SU", "15BI>P0001rCgUD58DRalRj:00S5",
>> "15BkV00P00rCQBf5:Q5JQOv42D1o", "15BW=20P00JCrvH54t=an?vB00Sg",
>> "15D8Gj0P00rCThP5:6T=2Ov>0 using 5H", "15De7F?P00JCr5r5517v4?v80h2P",
>> "15E:BR0P00rCgaT58DdJUwv82H34", "15E:N using 0000rCgOd57p45bW><0<2H",
>> "15E=m60000rC`W459k28Wnd:083h", "15E=q08P00JCrnR52cb>4?v200Sw",
>> "15PoOh0001rCgbt58CwUaBD004`0", "15PvE using 0002rCi7R57pokCT:424`0",
>> "15Q69 using 8000rCiDr57n`bp using tB2<4R", "15QCl@?P?w<tSF0l4Q@>4?wp0 using 5:",
>> "15QDCP0P?w<tSF0l4Q@>4?wp0D1G", "15QIK`0P00rC`Sb59jFUUgv02<1g",
>> "15QK900001JCq=d54l?5J0op0l4e", "15QtF00000rCafD59P?VJ9p<0H52",
>> "15TGcJ0002rD<>p55FgmI using Ul0H0S", "15TgVb0000rCgVb57oFc;ARF2 using 67",
>> "15TgVb0000rCgVd57oFc31R42L46", "15TILd?P00JCm4l53`D>4?v>0L1m",
>> "15U?B00000rCgb>58DFJfRl620RT", "15U using cn0000rCgU>57oPLGiT:2D4D",
>> "15UHOn9P00rCQ`D5:OcTkgv80<4:", "1819?@H001rC9TB5=bppM9<82D0T",
>> "18K1kH000FrCSMt5:@;m>l8>0<4J", "19NSFKh000JCTeH5:7g1LT8:0`3g",
>> "19NSG<h003rCi@:57pmUkAB<0<1v", "1gu00CLLwfh2 using Asw9@1<",
>> "1gu103LLwfl1 using Asw9P1<",
>> "3", "34`odN1000rD1V2537=dfPJ60000", "35A=Rh1001rD;s454vSTuP`40000",
>> "35QN<D1000rCr5l53esbgPR20000", "39NS using m11@1rCrb:53:E<v0j3R000",
>> "403Iu6Qv4PU00rCk0d57rwW00<2g", "403Iu6Qv4PU01rCk0d57rwW00<2g",
>> "403Iupiv4PU00rC9065>=fW00H0I", "403Iupiv4PU00rC9065>=fW00H0j",
>> "54aMBf02:9M`?IDOH018DL4j085T000000000016>`Q8>4Oc0?@lRDm3hPC0",
>> "55AP::02 using VAlQ3G;7:1<lUB0MD4 using DhuE0F22220l0`G465k90<PlRDm3hPC8",
>> "55B7iD42CSGC<H`WF20L5>1=@5:222222222221 using G@W9K4Oi0D using PC0ShK40C",
>> "55R4:002?H<`Q3S7GR1<lUB0 using 4pF22222222220l000004p60;0E7kBE8888",
>> "7933.8835099999997", "7933.8836099999999",
>> "803Iu6PF15REPH3 using Dh000000000002c88I2P0002IrbQ0@40TW`800000000",
>> "85E:BR0F0P0000000000032jS2P000000DE7P3A00h0", "88888888880",
>> "A03IupkAC4:dH0N90C9p0goOwj<Cw`P05A7vnh081wqU05DFwAKw<0?va using 1>",
>> "A03IupkAC4:dH0N90D=p0goP02<Cw``05A7vnwt81wqVwUDFwAOt<0?vah1>",
>> "A03IupkAC4:dH0v90>@P1cF6nud using NrP5wH5T",
>> "A03IupkAC4:dH0v90FtP1cF6nud using NrP5wH5T",
>> "B;s using N9h00>TtPEQAslh03wuUwP06", "B;s using N9h00>TtPF1Asll03wP5wP06",
>> "B;s using N9h00>TtPF1Asll03wPUwP06", "B;s using N9h00>TtPF1Aslp03wQ5wP06",
>> "B;s using N9h00>TtPFQAslt03wQUwP06", "B;s using N9h00>TtPFQAslt03wR5wP06",
>> "B;s using N9h00>TtPFQAsm003wRUwP06", "B;s using N9h00>TtPFQAsm803wU5wP06",
>> "B;s using N9h00>TtPG1Asm403wSUwP06", "B;s using N9h00>TtPG1Asm403wT5wP06",
>> "B;s using N9h00>TtPG1Asm803wTUwP06", "D03Iu6QGLN01MdN01StN000",
>> "D03Iuph1TNfp4dv9J<`N000",
>> "H5?AU:4U653hhhi8 using lkihP000000",
>> "HGp0772K07N4d1;0Pf71r0aj19RVmR19RVuR19RW5R19RW;t91Cjp31000C4",
>> "PC using H8888880"), class = "factor")), class = "data.frame", row.names =
>> c(NA,
>> -100L))
>>
>> Each one of those weird codes given in the AISMessageFrame correspond to
>> an AIS message, there is a lot of information provided here, but I am only
>> concerned with the Latitude and Longitude values (degrees with minutes). In
>> order to accomplish this, each one of those wierd codes need to be
>> converted to binary strings, once converted to binary strings. As I
>> mentioned before, the information regarding latitude and longitude can be
>> extracted from the following positions (again, after converting code to
>> binary strings):
>> Latitude = positions 90 to 116 inclusive (assuming you count the bits
>> from left to right, with the first one having position number 1)
>> Longitude = positions 62 to 89 inclusive (assuming you count the bits
>> from left to right withe the first one having position number 1)
>>
>> In the sample code I provided in previous emails, I used the following to
>> obtain the Latitude and Longitude:
>>
>> library(stringi)
>> library(dplyr)
>> library(R.utils)
>> library(RANN)
>> library(NISTunits)
>> library(pracma)
>> library(celestial)
>> library(stringr)
>>
>> #here I show the sample to decode a single record, though that needs to
>> be done for all AIS messages, so obviously a loop will be needed for that:
>>
>> ascii_datformat <- utf8ToInt(dataset1[1,6]) #turning the first AIS
>> message as it comes to ascii number
>> Base <- ascii_datformat - 48    #transformation from ascii to decimal
>> decy <- ifelse(Base > 40, Base-8, Base) #transformation from ascii to
>> decimal continued
>> biny <- intToBin(decy)  #transformation from decimal to binary
>> representation
>> binyframe <- data.frame(biny)
>> tbinyframe <- paste(t(binyframe[,1]), collapse="") #simply transposing
>> the results
>>
>> tbinyframe will give you something like this (for each row having an AIS
>> message)
>> > tbinyframe
>> [1]
>> "000001000101001111101110000101011000001111100000000000000000111010010011100001101001111100000101001010011111101001110000000000001111111111110110000010010000100011000110"
>>
>> Latitude <- substr(tbinyframe, 90, 116)
>> Longitude <- substr(tbinyframe, 62, 89)
>>
>> What I need is to decode thos latitude and longitude values , to get
>> results in a -90 to +90 range for latitude, and in the -180 to +180 range
>> for longitude.
>>
>> Hopefully I´ve made myself sufficiently clear this time and/or hopefully
>> I understood your point correctly and provided you what you need.
>>
>> Again, thank you so much for your time and valuable support brother!
>>
>> Best regards,
>>
>> Paul
>>
>> El vie., 24 ene. 2020 a las 14:09, Richard M. Heiberger (<rmh using temple.edu>)
>> escribió:
>>
>>> now I am even more puzzled.
>>>
>>> please complete the following two data.frames and send it to the list.
>>>
>>> latDegrees lat2Comp
>>> -90 xxxxxxxx
>>> -89 xxxxxxxx
>>> ...
>>> -1 xxxxxxxx
>>> 0 xxxxxxxx
>>> 1 xxxxxxxx
>>> ...
>>> 89 xxxxxxxx
>>> 90 xxxxxxxx
>>>
>>> lonDegrees lon2Comp
>>> -180 xxxxxxxx
>>> -179 xxxxxxxx
>>> ...
>>> -91 xxxxxxxx
>>> -90 xxxxxxxx
>>> -89 xxxxxxxx
>>> ...
>>> -1 xxxxxxxx
>>> 0 xxxxxxxx
>>> 1 xxxxxxxx
>>> ...
>>> 89 xxxxxxxx
>>> 90 xxxxxxxx
>>> 91 xxxxxxxx
>>> ...
>>> 179 xxxxxxxx
>>> 180 xxxxxxxx
>>>
>>> Your 8 bit 2C example has 7 digits of precision plus sign which gives
>>> a range of (-127,127).  That suffices for latitude (-90,90).
>>> For longitude you will need 9 bits of twos complement for 8 bits of
>>> precision plus sign to cover (-255,255), thus more than enough for
>>> (-180,180).
>>> This assumes that precision to the degree is sufficient.  If you need
>>> precision to minutes and seconds, or to meters, then you
>>> will need even more bits in 2C.
>>>
>>> Since it looks like you need a different number of bits for each
>>> variable, I am asking for two data.frames.
>>>
>>> Rich
>>>
>>> On Fri, Jan 24, 2020 at 1:46 PM Paul Bernal <paulbernal07 using gmail.com>
>>> wrote:
>>> >
>>> > 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 range
>>> from -90 to + 90, and -180 to +180).
>>> >
>>> > Regards,
>>> >
>>> > Paul
>>> >
>>> > El vie., 24 ene. 2020 a las 12:23, Richard M. Heiberger (<
>>> rmh using temple.edu>) escribió:
>>> >>
>>> >> 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, Jan 24, 2020 at 11:34 AM Paul Bernal <paulbernal07 using gmail.com>
>>> wrote:
>>> >> >
>>> >> > 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 function you provided me in one of your replies, and it
>>> works
>>> >> > well with the examples  you provided, but in other cases it doesn´t.
>>> >> >
>>> >> > The messages I am trying to decode are in the 6th column of the
>>> data. I
>>> >> > will provide you with a small sample first, and then the complete
>>> dataset
>>> >> > (which has 100 rows). This is the small sample:
>>> >> >
>>> >> > > head(dat)
>>> >> >     ...1 ...2 ...3 ...4 ...5                         ...6 ...7
>>>  ...8
>>> >> > ...9 ...10 ...11 ...12 ...13
>>> >> > 1 !AIVDM    1    1   NA    A 15?f5H?P00rCQat5:Oah0?wn2 using S6 0*54
>>> 1485907200
>>> >> > <NA>    NA    NA    NA  <NA>
>>> >> > 2 !AIVDM    1    1   NA    A 1349B:3000rCtrn553aR using JH02PRp 0*39
>>> 1485907200
>>> >> > <NA>    NA    NA    NA  <NA>
>>> >> > 3 !AIVDM    1    1   NA    A      D03Iuph1TNfp4dv9J<`N000 2*0D
>>> 1485907200
>>> >> > <NA>    NA    NA    NA  <NA>
>>> >> > 4 !AIVDM    1    1   NA    A      D03Iu6QGLN01MdN01StN000 2*43
>>> 1485907200
>>> >> > <NA>    NA    NA    NA  <NA>
>>> >> > 5 !AIVDO    1    1   NA <NA> B;s using N9h00>TtPEQAslh03wuUwP06 0*29
>>> 1485907200
>>> >> > <NA>    NA    NA    NA  <NA>
>>> >> > 6 !AIVDM    1    1   NA    A 15A using av3P00rClHn53<I8M?v02<2B 0*2D
>>> 1485907200
>>> >> > <NA>    NA    NA    NA  <NA>
>>> >> >
>>> >> > It is worth mentioning that each row of the 6th column provides
>>> several
>>> >> > information about maritime vessels, like speed over ground,
>>> latitude,
>>> >> > longitude, vessel ID, etc. I am only concerned with latitude and
>>> longitude
>>> >> > since those are the only two fields I have not been able to decode
>>> >> > successfully. Also, I am working on R version 3.6.2 for windows
>>> 64-bit OS.
>>> >> >
>>> >> > The messages to decode are of the following format:
>>> >> > 15?f5H?P00rCQat5:Oah0?wn2 using S6,  1349B:3000rCtrn553aR using JH02PRp, etc.
>>> >> >
>>> >> > Now, here is the complete dataset:
>>> >> >
>>> >> > > dput(dat)
>>> >> > structure(list(...1 = c("!AIVDM", "!AIVDM", "!AIVDM", "!AIVDM",
>>> >> > "!AIVDO", "!AIVDM", "!AIVDM", "!AIVDM", "!AIVDM", "!AIVDM",
>>> "!AIVDM",
>>> >> > "!AIVDM", "!AIVDM", "!AIVDM", "!AIVDM", "!AIVDO", "!AIVDM",
>>> "!AIVDM",
>>> >> > "!AIVDM", "!AIVDM", "!AIVDM", "!AIVDM", "!AIVDM", "!AIVDM",
>>> "!AIVDM",
>>> >> > "!AIVDO", "!AIVDM", "$GPRMC", "!AIVDM", "!AIVDM", "!AIVDM",
>>> "$GPGBS",
>>> >> > "!AIVDM", "!AIVDM", "!AIVDM", "!AIVDO", "!AIVDM", "!AIVDM",
>>> "!AIVDM",
>>> >> > "!AIVDM", "!AIVDM", "!AIVDM", "!AIVDM", "!AIVDO", "!AIVDM",
>>> "!AIVDM",
>>> >> > "!AIVDM", "!AIVDM", "!AIVDM", "!AIVDM", "!AIVDM", "!AIVDO",
>>> "!AIVDM",
>>> >> > "!AIVDM", "!AIVDM", "!AIVDM", "!AIVDM", "!AIVDM", "!AIVDM",
>>> "!AIVDM",
>>> >> > "!AIVDM", "!AIVDO", "$GPRMC", "!AIVDM", "!AIVDM", "!AIVDM",
>>> "!AIVDM",
>>> >> > "!AIVDM", "$GPGBS", "!AIVDM", "!AIVDM", "!AIVDM", "!AIVDO",
>>> "!AIVDM",
>>> >> > "!AIVDM", "!AIVDM", "!AIVDM", "!AIVDM", "!AIVDO", "!AIVDM",
>>> "!AIVDM",
>>> >> > "!AIVDM", "!AIVDM", "!AIVDM", "!AIVDM", "!AIVDM", "!AIVDO",
>>> "!AIVDM",
>>> >> > "!AIVDM", "!AIVDM", "!AIVDM", "!AIVDM", "!AIVDM", "!AIVDM",
>>> "!AIVDM",
>>> >> > "!AIVDM", "$GPRMC", "!AIVDO", "!AIVDM", "!AIVDM"), ...2 = c(1,
>>> >> > 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
>>> >> > 1, 1, 1, 1, 1, 50002, 1, 2, 2, 50002, 1, 1, 1, 1, 1, 1, 1, 1,
>>> >> > 1, 2, 2, 1, 1, 1, 1, 1, 1, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2,
>>> >> > 1, 50006, 1, 1, 1, 1, 1, 50006, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1,
>>> >> > 1, 1, 1, 1, 2, 2, 1, 1, 1, 2, 2, 1, 1, 1, 1, 1, 1, 50010, 1,
>>> >> > 1, 1), ...3 = c("1", "1", "1", "1", "1", "1", "1", "1", "1",
>>> >> > "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1",
>>> >> > "1", "1", "1", "1", "1", "A", "1", "1", "2", "1.3", "1", "1",
>>> >> > "1", "1", "1", "1", "1", "1", "1", "1", "2", "1", "1", "1", "1",
>>> >> > "1", "1", "1", "2", "1", "1", "1", "1", "1", "1", "1", "1", "1",
>>> >> > "2", "1", "A", "1", "1", "1", "1", "1", "1.3999999999999999",
>>> >> > "1", "2", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1",
>>> >> > "1", "1", "2", "1", "1", "1", "1", "2", "1", "1", "1", "1", "1",
>>> >> > "1", "A", "1", "1", "1"), ...4 = c(NA, NA, NA, NA, NA, NA, NA,
>>> >> > NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
>>> >> > NA, NA, NA, NA, 856.96783, NA, 7, 7, 1.5, NA, NA, NA, NA, NA,
>>> >> > NA, NA, NA, NA, 8, 8, NA, NA, NA, NA, NA, NA, 9, 9, NA, NA, NA,
>>> >> > NA, NA, NA, NA, NA, 0, 0, NA, 856.96805, NA, NA, NA, NA, NA,
>>> >> > 1.5, 1, 1, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 2,
>>> >> > 2, NA, NA, NA, 3, 3, NA, NA, NA, NA, NA, NA, 856.96827, NA, NA,
>>> >> > NA), ...5 = c("A", "A", "A", "A", NA, "A", "A", "B", "B", "A",
>>> >> > "A", "A", "A", "B", "B", NA, "B", "A", "B", "A", "B", "B", "A",
>>> >> > "B", "A", NA, "B", "N", "B", "A", "A", "3.2000000000000002",
>>> >> > "B", "A", "A", NA, "A", "A", "A", "A", "B", "A", "A", NA, "B",
>>> >> > "A", "A", "A", "A", "A", "A", NA, "A", "A", "A", "B", "B", "B",
>>> >> > "B", "A", "A", NA, "N", "A", "A", "B", "B", "B",
>>> "3.2999999999999998",
>>> >> > "B", "B", "B", NA, "B", "B", "A", "B", "B", NA, "B", "B", "A",
>>> >> > "A", "B", "B", "A", NA, "B", "B", "B", "A", "A", "A", "A", "A",
>>> >> > "B", "N", NA, "B", "B"), ...6 = c("15?f5H?P00rCQat5:Oah0?wn2 using S6",
>>> >> > "1349B:3000rCtrn553aR using JH02PRp", "D03Iuph1TNfp4dv9J<`N000",
>>> >> > "D03Iu6QGLN01MdN01StN000",
>>> >> > "B;s using N9h00>TtPEQAslh03wuUwP06", "15A using av3P00rClHn53<I8M?v02<2B",
>>> >> > "1000Fo using P01rCuG<56bnkN?v004`0", "15QK900001JCq=d54l?5J0op0l4e",
>>> >> > "15 using eD@8000rC`bl59kW`mFn004`0", "15QIK`0P00rC`Sb59jFUUgv02<1g",
>>> >> > "403Iupiv4PU00rC9065>=fW00H0I", "403Iu6Qv4PU00rCk0d57rwW00<2g",
>>> >> > "H5?AU:4U653hhhi8 using lkihP000000", "15TGcJ0002rD<>p55FgmI using Ul0H0S",
>>> >> > "15Aq00?P00rC`a`59mFeogv004`0", "B;s using N9h00>TtPF1Asll03wP5wP06",
>>> >> > "13P;K8 using Oh1rCfgp58=ec1bD22<4J", "139NL4000LrCc8j59FEED4 using 000S<",
>>> >> > "403Iupiv4PU00rC9065>=fW00H0j", "39NS using m11@1rCrb:53:E<v0j3R000",
>>> >> > "403Iu6Qv4PU01rCk0d57rwW00<2g", "15PvE using 0002rCi7R57pokCT:424`0",
>>> >> > "15TgVb0000rCgVd57oFc31R42L46", "15PoOh0001rCgbt58CwUaBD004`0",
>>> >> > "A03IupkAC4:dH0v90>@P1cF6nud using NrP5wH5T", "B;s using N9h00
>>> >TtPF1Asll03wPUwP06",
>>> >> > "15E=q08P00JCrnR52cb>4?v200Sw", "7933.8836099999999",
>>> >> > "15>uP00P00rC`U:59im;H?v22 using 1D",
>>> >> > "54aMBf02:9M`?IDOH018DL4j085T000000000016>`Q8>4Oc0?@lRDm3hPC0",
>>> >> > "3", NA, "1018lEWP?w<tSF0l4Q@>4?wp0W3h",
>>> "15BkV00P00rCQBf5:Q5JQOv42D1o",
>>> >> > "35QN<D1000rCr5l53esbgPR20000", "B;s using N9h00>TtPF1Aslp03wQ5wP06",
>>> >> > "34`odN1000rD1V2537=dfPJ60000", "15>nNj0000rCT<@5::qUpkt604`0",
>>> >> > "15UHOn9P00rCQ`D5:OcTkgv80<4:", "35A=Rh1001rD;s454vSTuP`40000",
>>> >> > "15U?B00000rCgb>58DFJfRl620RT",
>>> "55B7iD42CSGC<H`WF20L5>1=@5:222222222221 using G
>>> >> > @W9K4Oi0D using PC0ShK40C",
>>> >> > "PC using H8888880", "B;s using N9h00>TtPFQAslt03wQUwP06",
>>> >> > "15De7F?P00JCr5r5517v4?v80h2P",
>>> >> > "15U using cn0000rCgU>57oPLGiT:2D4D", "137g`F8007rCaIj59Tc5Dl using 800SN",
>>> >> > "15?7P`0P00rD1S453KSlj?v824`0", "15?mqH?P00rCek458rkEN?v:00S4",
>>> >> > "55R4:002?H<`Q3S7GR1<lUB0 using 4pF22222222220l000004p60;0E7kBE8888",
>>> >> > "88888888880", "B;s using N9h00>TtPFQAslt03wR5wP06",
>>> >> > "15E:BR0P00rCgaT58DdJUwv82H34",
>>> >> > "15AIw`0P0GrCcO859DO5Ogv:0T`0", "14aMBf000wrCKKN5:sdU0Sv<083C",
>>> >> > "1819?@H001rC9TB5=bppM9<82D0T", "13M using Hk00jSJD@RD4s=qG1mT80 using 3J",
>>> >> > "15BI>P0001rCgUD58DRalRj:00S5", "100000?P00JCkt:583J=r?v:283Q",
>>> >> > "A03IupkAC4:dH0N90C9p0goOwj<Cw`P05A7vnh081wqU05DFwAKw<0?va using 1>",
>>> >> > "1gu00CLLwfh2 using Asw9@1<", "B;s using N9h00>TtPFQAsm003wRUwP06",
>>> >> > "7933.8835099999997",
>>> >> > "18K1kH000FrCSMt5:@;m>l8>0<4J", "19NSFKh000JCTeH5:7g1LT8:0`3g",
>>> >> > "15E=m60000rC`W459k28Wnd:083h", "1:u0KOh001rCq5P529qqubqh2 using 3n",
>>> >> > "13P>4mhw1CrCi5H57aK5WlN>0<4F", NA,
>>> >> > "A03IupkAC4:dH0N90D=p0goP02<Cw``05A7vnwt81wqVwUDFwAOt<0?vah1>",
>>> >> > "1gu103LLwfl1 using Asw9P1<", "14S8 using n001LrD?bH53iGe1rN>0 using 49",
>>> >> > "B;s using N9h00>TtPG1Asm403wSUwP06",
>>> >> >
>>> >> > "15E:N using 0000rCgOd57p45bW><0<2H", "15 using EA<0P01JCo8l53=BFgwv using 0D47",
>>> >> > "10007NgP00rCQGV5:Pa=?gv>2<1H", "15TILd?P00JCm4l53`D>4?v>0L1m",
>>> >> > "19NSG<h003rCi@:57pmUkAB<0<1v", "B;s using N9h00>TtPG1Asm403wT5wP06",
>>> >> > "15Q69 using 8000rCiDr57n`bp using tB2<4R", "15QtF00000rCafD59P?VJ9p<0H52",
>>> >> > "15QCl@?P?w<tSF0l4Q@>4?wp0 using 5:", "15QDCP0P?w<tSF0l4Q@>4?wp0D1G",
>>> >> > "803Iu6PF15REPH3 using Dh000000000002c88I2P0002IrbQ0@40TW`800000000",
>>> >> > "HGp0772K07N4d1;0Pf71r0aj19RVmR19RVuR19RW5R19RW;t91Cjp31000C4",
>>> >> > "15D8Gj0P00rCThP5:6T=2Ov>0 using 5H", "B;s using N9h00>TtPG1Asm803wTUwP06",
>>> >> > "15ATk20000rCnrv53N6;gPr>085R",
>>> >> > "55AP::02 using VAlQ3G;7:1<lUB0MD4 using DhuE0F22220l0`G465k90<PlRDm3hPC8",
>>> >> >
>>> >> > "88888888880", "15?lSL?P00JCQWD5:OpP0?vB24`0",
>>> >> > "15BW=20P00JCrvH54t=an?vB00Sg",
>>> >> > "13P;K8 using 001rCfgr58=f;QbFD2D4G",
>>> "A03IupkAC4:dH0v90FtP1cF6nud using NrP5wH5T",
>>> >> > "85E:BR0F0P0000000000032jS2P000000DE7P3A00h0",
>>> "1349B:3000rCtrn553aR using JHD2d4O",
>>> >> >
>>> >> > "7933.8835099999997", "B;s using N9h00>TtPFQAsm803wU5wP06",
>>> >> > "15B3Sj0000rC9RD5=mOh40jB20SU",
>>> >> > "15TgVb0000rCgVb57oFc;ARF2 using 67"), ...7 = c("0*54", "0*39", "2*0D",
>>> >> > "2*43", "0*29", "0*2D", "0*27", "0*1D", "0*26", "0*48", "0*4B",
>>> >> > "0*3A", "0*34", "0*3A", "0*76", "0*0B", "0*4A", "0*72", "0*6B",
>>> >> > "0*4E", "0*38", "0*04", "0*11", "0*17", "0*18", "0*6B", "0*64",
>>> >> > "W", "0*53", "0*32", "2*20", NA, "0*61", "0*1C", "0*79", "0*16",
>>> >> > "0*44", "0*53", "0*04", "0*2D", "0*1C", "0*07", "2*37", "0*12",
>>> >> > "0*2D", "0*30", "0*6D", "0*25", "0*26", "0*75", "2*2D", "0*71",
>>> >> > "0*38", "0*6D", "0*0F", "0*34", "0*1D", "0*70", "0*47", "0*70",
>>> >> > "0*4C", "0*54", "W", "0*64", "0*66", "0*69", "0*0C", "0*70",
>>> >> > NA, "0*11", "0*28", "0*38", "0*30", "0*1F", "0*64", "0*7C", "0*38",
>>> >> > "0*67", "0*57", "0*59", "0*75", "0*52", "0*18", "0*08", "0*5F",
>>> >> > "0*26", "0*3B", "0*67", "0*6A", "2*24", "0*47", "0*65", "0*56",
>>> >> > "0*54", "2*76", "0*23", "W", "0*3B", "0*1D", "0*11"), ...8 =
>>> c(1485907200,
>>> >> > 1485907200, 1485907200, 1485907200, 1485907200, 1485907200,
>>> 1485907200,
>>> >> > 1485907200, 1485907200, 1485907200, 1485907200, 1485907200,
>>> 1485907200,
>>> >> > 1485907201, 1485907201, 1485907201, 1485907201, 1485907201,
>>> 1485907201,
>>> >> > 1485907201, 1485907201, 1485907201, 1485907201, 1485907201,
>>> 1485907201,
>>> >> > 1485907201, 1485907201, 0.008, 1485907201, 1485907201, 1485907201,
>>> >> > NA, 1485907203, 1485907203, 1485907203, 1485907203, 1485907203,
>>> >> > 1485907203, 1485907203, 1485907204, 1485907204, 1485907204,
>>> 1485907204,
>>> >> > 1485907204, 1485907204, 1485907204, 1485907204, 1485907204,
>>> 1485907204,
>>> >> > 1485907204, 1485907205, 1485907205, 1485907205, 1485907205,
>>> 1485907205,
>>> >> > 1485907205, 1485907205, 1485907206, 1485907206, 1485907206,
>>> 1485907206,
>>> >> > 1485907206, 0.01, 1485907206, 1485907206, 1485907206, 1485907206,
>>> >> > 1485907206, NA, 1485907206, 1485907206, 1485907206, 1485907206,
>>> >> > 1485907206, 1485907206, 1485907206, 1485907208, 1485907208,
>>> 1485907208,
>>> >> > 1485907208, 1485907208, 1485907209, 1485907209, 1485907209,
>>> 1485907209,
>>> >> > 1485907209, 1485907209, 1485907209, 1485907209, 1485907209,
>>> 1485907209,
>>> >> > 1485907209, 1485907209, 1485907209, 1485907209, 1485907209, 0.005,
>>> >> > 1485907209, 1485907209, 1485907209), ...9 = c(NA, NA, NA, NA,
>>> >> > NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
>>> >> > NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, "*41", NA, NA, NA,
>>> >> > NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
>>> >> > NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
>>> >> > NA, "*43", NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
>>> >> > NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
>>> >> > NA, NA), ...10 = c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
>>> >> > NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
>>> >> > 10217, NA, NA, NA, 1485907201, NA, NA, NA, NA, NA, NA, NA, NA,
>>> >> > NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
>>> >> > NA, NA, NA, NA, NA, NA, 10217, NA, NA, NA, NA, NA, 1485907206,
>>> >> > NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
>>> >> > NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 10217, NA, NA, NA
>>> >> > ), ...11 = c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
>>> >> > NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
>>> >> > NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
>>> >> > NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
>>> >> > NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
>>> >> > NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
>>> >> > NA, NA, NA, NA, NA, NA, NA, NA), ...12 = c(NA, NA, NA, NA, NA,
>>> >> > NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
>>> >> > NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
>>> >> > NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
>>> >> > NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
>>> >> > NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
>>> >> > NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA),
>>> >> >     ...13 = c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
>>> >> >     NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
>>> >> >     "D*6F", NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
>>> >> >     NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
>>> >> >     NA, NA, NA, NA, NA, NA, "D*60", NA, NA, NA, NA, NA, NA, NA,
>>> >> >     NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
>>> >> >     NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, "D*63", NA, NA,
>>> >> >     NA), ...14 = c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
>>> >> >     NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
>>> >> >     NA, 1485907201, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
>>> >> >     NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
>>> >> >     NA, NA, NA, NA, NA, NA, NA, NA, 1485907206, NA, NA, NA, NA,
>>> >> >     NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
>>> >> >     NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
>>> 1485907209,
>>> >> >     NA, NA, NA)), row.names = c(NA, -100L), class = "data.frame")
>>> >> >
>>> >> > To tested your function I took the first message, which is located
>>> in the
>>> >> > 6th column and the 1st row, and did the following:
>>> >> >
>>> >> > library(stringi)
>>> >> > library(dplyr)
>>> >> > library(R.utils)
>>> >> > library(RANN)
>>> >> > library(NISTunits)
>>> >> > library(pracma)
>>> >> > library(celestial)
>>> >> > library(stringr)
>>> >> >
>>> >> > dat <- readXL("U:/RawSampleData.xls", rownames=FALSE, header=FALSE,
>>> na="",
>>> >> > +   sheet="RawSampleData", stringsAsFactors=FALSE)
>>> >> >
>>> >> > testmessage1 <- dat[1,6]
>>> >> >
>>> >> > ascii_datformat <- utf8ToInt(testmessage1)
>>> >> >
>>> >> > Base <- ascii_datformat - 48
>>> >> >
>>> >> > decy <- ifelse(Base > 40, Base - 8, Base)
>>> >> >
>>> >> > biny <- intToBin(decy)
>>> >> >
>>> >> > binyframe <- data.frame(biny)
>>> >> >
>>> >> > tbinyframe <- paste(t(binyframe[,1]), collapse="")  #at this point,
>>> I have
>>> >> > the complete first message, all in binary format
>>> >> >
>>> >> > #according to the literature of AIS message decoding, longitude
>>> goes from
>>> >> > position 62 to position 89
>>> >> > #and latitude goes from position 90 to position 116
>>> >> >
>>> >> > longitude <- substr(tbinyframe, 62, 89)
>>> >> > latitude    <- substr(tbinyframe, 90, 116)
>>> >> >
>>> >> > #now I apply the function you provided me with:
>>> >> >
>>> >> >  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(res)
>>> >> >       }
>>> >> >
>>> >> > > fun(longitude)
>>> >> > [1] 220663102
>>> >> > >
>>> >> > > fun(latitude)
>>> >> > [1] 5414823
>>> >> > >
>>> >> > > fun("1101001001110000110100111110")
>>> >> > [1] 220663102
>>> >> > >
>>> >> > > fun("000010100101001111110100111")
>>> >> > [1] 5414823
>>> >> > >
>>> >> > > fun("10110010")
>>> >> > [1] -78
>>> >> >
>>> >> > as you can see, the function only worked or showed expected result
>>> on the
>>> >> > last case with a -78, but in the other cases, it the results were
>>> not as
>>> >> > expected, maybe I am missing something here?
>>> >> >
>>> >> > Any help and/or guidance will be greatly appreciated,
>>> >> >
>>> >> > Best regards,
>>> >> >
>>> >> > Paul
>>> >> >
>>> >> > El lun., 20 ene. 2020 a las 10:28, Rui Barradas (<
>>> ruipbarradas using sapo.pt>)
>>> >> > escribió:
>>> >> >
>>> >> > > 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
>>> >> > > conversion is done as follows:
>>> >> > >
>>> >> > > input: 10110010
>>> >> > >
>>> >> > > splitting, to make it more clear:
>>> >> > >
>>> >> > > 1 0 1 1 0 0 1 0 - input
>>> >> > > 0 1 0 0 1 1 0 1 - reversed
>>> >> > >                1 - add 1 to the number with reversed bits
>>> >> > > 0 1 0 0 1 1 1 0 - result is the two's complement
>>> >> > >
>>> >> > > c(0, 1, 0, 0, 1, 1, 1, 0) %*% 2^(7:0) is 78
>>> >> > >
>>> >> > > But the msb is "1" so it's -78
>>> >> > >
>>> >> > >
>>> >> > > This is what the function does, but instead of %*% it uses
>>> >> > >
>>> >> > > sum(two's compl * powers of two)
>>> >> > >
>>> >> > >
>>> >> > > Hope this helps,
>>> >> > >
>>> >> > > Rui Barradas
>>> >> > >
>>> >> > > The input must be a character string or character vector.
>>> >> > >
>>> >> > > Às 14:36 de 20/01/20, Paul Bernal escreveu:
>>> >> > > > 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 number (10110010) into the two´s
>>> >> > > > complement representation, there is the logic they are using
>>> for that.
>>> >> > > > Since longitude ranges from
>>> >> > > >
>>> >> > > >
>>> >> > > >       Example of conversion to decimal of a signed binary
>>> number in
>>> >> > > >       two's complement representation
>>> >> > > >
>>> >> > > > Let's convert to decimal the following signed binary number:
>>> 10110010
>>> >> > > >
>>> >> > > > 10110010 = -1×27 + 0×26 + 1×25 + 1×24 + 0×23 + 0×22 + 1×21 +
>>> 0×20 = -128
>>> >> > > > + 32 + 16 + 2 = -78.
>>> >> > > >
>>> >> > > > El lun., 20 ene. 2020 a las 7:22, Rui Barradas (<
>>> ruipbarradas using sapo.pt
>>> >> > > > <mailto:ruipbarradas using sapo.pt>>) escribió:
>>> >> > > >
>>> >> > > >     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(res)
>>> >> > > >     }
>>> >> > > >
>>> >> > > >     fun("10110010")
>>> >> > > >     fun("10000000")
>>> >> > > >     fun(c("01000000", "01111111", "10110010", "10000000"))
>>> >> > > >
>>> >> > > >
>>> >> > > >     Hope this helps,
>>> >> > > >
>>> >> > > >     Rui Barradas
>>> >> > > >
>>> >> > > >     Às 11:38 de 20/01/20, Rui Barradas escreveu:
>>> >> > > >      > 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 will be greatly appreciated,
>>> >> > > >      >>
>>> >> > > >      >> Best regards,
>>> >> > > >      >>
>>> >> > > >      >> Paul
>>> >> > > >      >>
>>> >> > > >      >>     [[alternative HTML version deleted]]
>>> >> > > >      >>
>>> >> > > >      >> ______________________________________________
>>> >> > > >      >> R-help using r-project.org <mailto:R-help using r-project.org>
>>> mailing list
>>> >> > > >     -- To UNSUBSCRIBE and more, see
>>> >> > > >      >> 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.
>>> >> > > >      >>
>>> >> > > >      >
>>> >> > > >      > ______________________________________________
>>> >> > > >      > R-help using r-project.org <mailto:R-help using r-project.org>
>>> mailing list
>>> >> > > >     -- To UNSUBSCRIBE and more, see
>>> >> > > >      > 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.
>>> >> > > >
>>> >> > >
>>> >> >
>>> >> >         [[alternative HTML version deleted]]
>>> >> >
>>> >> > ______________________________________________
>>> >> > R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>> >> > 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.
>>>
>>

	[[alternative HTML version deleted]]



More information about the R-help mailing list