Skip to content

Instantly share code, notes, and snippets.

@tachoknight
Last active July 18, 2024 23:03
Show Gist options
  • Save tachoknight/926ba81718f4e15f8e8655146a2dfb70 to your computer and use it in GitHub Desktop.
Save tachoknight/926ba81718f4e15f8e8655146a2dfb70 to your computer and use it in GitHub Desktop.
RFID Tag converter
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
}
@tachoknight
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment