Last active
July 18, 2024 23:03
-
-
Save tachoknight/926ba81718f4e15f8e8655146a2dfb70 to your computer and use it in GitHub Desktop.
RFID Tag converter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"strconv" | |
) | |
func main() { | |
var err error | |
// Want to go from 123456 (what reader says) | |
// to 157920 (what the door system expects) | |
n := int64(123456) | |
bins := strconv.FormatInt(n, 2) | |
bins = fmt.Sprintf("%024s", bins) | |
fmt.Println(bins) | |
frontb := bins[0:8] | |
backb := bins[len(bins)-16:] | |
fmt.Println(frontb) | |
fmt.Println(backb) | |
f, err := strconv.ParseInt(frontb, 2, 32) | |
if err != nil { | |
fmt.Println(err) | |
} | |
b, err := strconv.ParseInt(backb, 2, 32) | |
if err != nil { | |
fmt.Println(err) | |
} | |
final := fmt.Sprintf("%d%d", f, b) | |
fmt.Println(final) // Should be 157920 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This bit of code is how to convert from the number registered by the RFID reader to the format that the UHPPOTE door entry system wants.