c - Bitwise multiplication to achieve result -
is there general set of rules achieve number multiplying known , unknown number. e.g. suppose x = 13 , z = 9
is there way find y such
x * y = z => 13 * y = 9
i don't want utilize them mathematical integers, rather in terms of bits. so, want keep z int. obviously, there overflow in bit representation, i'm unsure how find z without brute forcing values in 32-bit machine. think y small number, negative.
note: isn't or hw assignment, change x , y whatever, these examples.
first, find modular multiplicative inverse of x
(13) mod 232. there several ways it, many people recommend extended euclidean algorithm, not simplest case. see hacker's delight chapter 10 (integer division constants) simpler algorithm.
anyway, once know modular multiplicative inverse of 13 mod 232 0xc4ec4ec5
, multiply number z
y
.
0xc4ec4ec5 * 9 = 0xec4ec4ed
so y = 0xec4ec4ed
, , 0xec4ec4ed * 13
indeed 9.
note if x
even, has no inverse. if it's "at z
" (that is, has many or fewer trailing zeroes z
) can solve way after dividing out highest common power of 2.
Comments
Post a Comment