Discussion:
idiomatic way to turn "10101000" to a byte?
Tai Trinh
2012-01-02 10:18:21 UTC
Permalink
Whats the idiomatic way to turn a string of say "10101000" to a byte.

(right now im just iterating over the string and setting the bits of a
byte)

-Tai
minux
2012-01-02 10:25:52 UTC
Permalink
Post by Tai Trinh
Whats the idiomatic way to turn a string of say "10101000" to a byte.
func Btoi64 and Btoui64 in strconv package.
Tai Trinh
2012-01-02 10:37:32 UTC
Permalink
Ok thanks. Like so, right:

r,e := strconv.Btoui64("10101000", 2)
b := byte(r)

-Tai
Post by minux
Post by Tai Trinh
Whats the idiomatic way to turn a string of say "10101000" to a byte.
func Btoi64 and Btoui64 in strconv package.
ps
2012-01-02 12:47:00 UTC
Permalink
I think the new way (Btoui64 appears to be gone) would be:

r,e := strconv.ParseInt("10101000", 2, 0)
b := byte(r)
Post by Tai Trinh
r,e := strconv.Btoui64("10101000", 2)
b := byte(r)
-Tai
Post by minux
Post by Tai Trinh
Whats the idiomatic way to turn a string of say "10101000" to a byte.
func Btoi64 and Btoui64 in strconv package.
ps
2012-01-02 12:45:04 UTC
Permalink
I think the new way (Btoui64 appears to be gone) would be:

r,e := strconv.ParseInt("10101000", 2, 0)
b := byte(r)
Post by Tai Trinh
r,e := strconv.Btoui64("10101000", 2)
b := byte(r)
-Tai
Vadik Vygonets
2012-01-02 23:47:24 UTC
Permalink
Post by ps
r,e := strconv.ParseInt("10101000", 2, 0)
r,e := strconv.ParseUint("10101000", 2, 8)

Loading...