Hello,
im facing a problem. i’m trying to convert 400(dec) into Byte, but i get an error like: FAIL : Creating bytes failed: Integer ‘400’ cannot be represented as a byte.
any help will be good
Hello,
im facing a problem. i’m trying to convert 400(dec) into Byte, but i get an error like: FAIL : Creating bytes failed: Integer ‘400’ cannot be represented as a byte.
any help will be good
One byte by definition can only hold up to 255 (dec), so you need to represent the number in two bytes.
You only show the error, but not the code that causes, and my guessing powers are very limited :).
Hello @HelioGuilherme66 sorry. below you can see the code:
${list} Create List 64 400
${payload} Convert To Bytes ${list} int
im getting this error: FAIL : Creating bytes failed: Integer ‘400’ cannot be represented as a byte.
i have represented 400(dec) as 2 bytes like (01 90), but the representation as decimal will be 1 144(dec) instead of 400(dec) as before.
thanks in advance
Evrard
When you do:
${list}= Create List 64 400
You are getting a list of strings ==> [ “64”, “400” ]
In the Python code you would get a characters represented as bytes, by prepending a b
.
So what you really want is a list of byte characters, which would be in Python: [ b"64", b"400" ] or maybe “raw”, [ r"64", r"400" ].
I can’t go and see the details of Convert To Bytes, for now. Hope I gave some help.
Hello @HelioGuilherme66 even in python im not able to convert character b"400" as bytes. Im getting this error:
a = [b"400"]
val = bytearray(a)
Traceback (most recent call last):
File “”, line 1, in
TypeError: ‘bytes’ object cannot be interpreted as an integer
what i want to do is to encode 400 as a byte and send it to a specific component. The component has a function that will decode de payload and print it in decimal value. So i want to have 400(dec) as decimal value back from the function.
So you need to use Encode String To Bytes from the String library.