Ask Your Question
0

Is it possible to convert std_msgs/Int8 to a binary number?

asked 2016-10-31 12:49:43 -0600

215 gravatar image

I am currently trying to convert a std_msgs/Int8 messsage that I receive from a topic to a binary number in python.

The way I am currently doing it is by doing this dirty hack.

bin(int(str(data)))

but isn't there any nice way to do this? I mean this is python so something clever should be there...

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2016-10-31 12:56:36 -0600

ahendrix gravatar image

I'm not sure why you're converting to a string and then back to an int.

If you have an Int8, you should be able to call bin() on the data member directly:

# Import the Int8 message definition
from std_msgs.msg import Int8

# create an Int8 message and assign 32 to it
num = Int8()
num.data = 32

# call bin() on our Int8 data and print the result
print bin(num.data)
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2016-10-31 12:49:43 -0600

Seen: 330 times

Last updated: Oct 31 '16