they are the same except that there is something special for 不得已.
in fact 不得已 comes from the old chinese.
for the expression, 不得已而为之, u cant say 不得不而为之
而: to
为: do
之 : something which we have known.
example:
-why do u do this?
- 我不得已而为之
so, 我不得已而为之 = I have to.
anyway, 不得已而为之 is an old chinese expression which we still use today.
in old chinese, 已 means "control"
自已 means "to control myself"
不得已 means 不得自已
不得 means can not
不得自已 means can not control myself
we omit the 自, then it becomes 不得已.
so
不得已 + do something : can't control myself to do something (why can't I control myself? because something that I can't change or stop forces me to do something)
不得不 + do something : can't NOT to do something (double negative to express "have to do")
for u, u just need to know two things:
1) normally, they are the same.
2) 不得已而为之