# Overflow/underflow of []byte integer operations

i did read about byte operation here Opcodes - Algorand Developer Portal. so i think if need require large result number, i should use byte instead of uint64 (due to the value).
But i want to know what if the `+,*` failed on overflow or `-` operation failed on underflow for bytes (i see in uint operation it did)? what happended when they does not failed (the result will be unexpected)?

The byte integer operations `b+` and `b*` do not overflow. The result will just be larger than 64 bytes.
`b-` fails on underflow.

1 Like

I still have some confuse when reading the doc.

• with your answer `The byte integer operations `b+` and `b*` do not overflow ` so what happend with the return value (if the result more than 64 bytes)?
• The docs have this line `there is an implicit length limit of 128 bytes on outputs`, so does that mean the result of all operation (include b+,b*) must be less than 128 bytes, otherwise it will failed? or what happended with the return value?

The result is larger than 64 bytes.

It can never happen. When you add or multiply two 64-byte numbers, the result always fit in 128 bytes.

just for clear, for example with this pyteal operation `BytesDiv(BytesMul(a,b),c)`
If `a*b` exceed 64 bytes, then the `(a*b)/c` will be failed (since left argument (which is `a*b`)) exceed 64 bytes)? the same this happend with `b*,b+,b-`?

and speaking to operation, i want to ask what exactly `mulw , addw ` Opcodes - Algorand Developer Portal do?

can you give me some example, sorry for my bad understanding
Thanks

Yes, if a*b exceeds 64 bytes, the above operation will fail.
Note that it is â€śbytesâ€ť not â€śbitsâ€ť. 64 bytes = 512 bits, which is very very large.

(Remember uint64 = 64 bits = 8 bytes.)

`BytesMul` in PyTeal compiles to `b*`.
`BytesDiv` in PyTeal compiles to `b/`.
And so on.

1 Like

These are used if you donâ€™t want to use the `b...` operations.
Nowadays, I think `b...` are much easier.

1 Like

Thanks for your answer. i have another question that need to ask here for byte calculation here.
back to the scenario where i have BytesMul(a,b)
if `a*b` exceeds 64 bytes and i store the result in scratch slot or global/local slot (which defined as bytes), will it work?
If not, what does the result of `a*b` that exceeds 64 bytes can work? why doesnt it failed on overflow?

inputs of the `b+`, `b*`, â€¦ operations are limited to 64 bytes.
But outputs are not.
So `b*` output may be 128 bytes. There is never an overflow.

However, then you cannot use the 128-byte output in any of the `b+`, `b*`, â€¦ operations.

1 Like

A 128-byte string can be stored in scratchpad or in the global/local storage with key `""`, the empty key (since you have 128 bytes for both the key and the value together).