49.3 Gotchas in Base ConversionSay you want to convert between octal and hex, and you type: % It looks like something's gone haywire. 17 octal ought to be F hexadecimal, not 11. What's wrong? In fact, since you set ibase to octal before you set obase , what you really asked for was obase equal to 16 octal (14 decimal)! In short, always set obase before ibase , or you're in for a surprise. Similarly, suppose you'd set ibase to 16, and want to set it back to 10. You need to type: ibase=A not: ibase=10 Another thing to look out for is typing a hex digit when ibase is set to something other than 16. bc isn't smart enough to reject the input, and gives you back garbage. - |
|