Aditya Agrawal
Aditya Agrawal

Reputation: 167

How to wrap around in hexadecimal multiplication?

Like I'm multiplying 0xff with like 0x02, the resulting hex is going to be greater than 0xff. How do I make it wrap around to the beginning?

Upvotes: 0

Views: 237

Answers (1)

Jeffrey Scofield
Jeffrey Scofield

Reputation: 66823

As @ivg pointed out, hexadecimal is just a notation for integers. It's not a whole new kind of number. That might help figure things out a little easier.

The answer to this particular question is to use the mod operator:

# 271 mod 256;;
- : int = 15
# 0x10f mod 0x100;;
- : int = 15

Upvotes: 4

Related Questions