numbers.go 860 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package serial
  2. import (
  3. "strconv"
  4. )
  5. func Uint16ToBytes(value uint16, b []byte) []byte {
  6. return append(b, byte(value>>8), byte(value))
  7. }
  8. func Uint16ToString(value uint16) string {
  9. return strconv.Itoa(int(value))
  10. }
  11. func Uint32ToBytes(value uint32, b []byte) []byte {
  12. return append(b, byte(value>>24), byte(value>>16), byte(value>>8), byte(value))
  13. }
  14. func IntToBytes(value int, b []byte) []byte {
  15. return append(b, byte(value>>24), byte(value>>16), byte(value>>8), byte(value))
  16. }
  17. func IntToString(value int) string {
  18. return Int64ToString(int64(value))
  19. }
  20. func Int64ToBytes(value int64, b []byte) []byte {
  21. return append(b,
  22. byte(value>>56),
  23. byte(value>>48),
  24. byte(value>>40),
  25. byte(value>>32),
  26. byte(value>>24),
  27. byte(value>>16),
  28. byte(value>>8),
  29. byte(value))
  30. }
  31. func Int64ToString(value int64) string {
  32. return strconv.FormatInt(value, 10)
  33. }