Bug 221869 - bc doesn't always convert ibase to obase correctly
Summary: bc doesn't always convert ibase to obase correctly
Status: Closed Not A Bug
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 11.1-STABLE
Hardware: Any Any
: --- Affects Some People
Assignee: freebsd-bugs mailing list
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-08-27 23:07 UTC by edgar
Modified: 2017-08-29 14:58 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description edgar 2017-08-27 23:07:46 UTC
While using bc to convert from binary to decimal I encountered this.

edgar@FreeBSD$ bc
ibase=2
obase=10
1111
1111

I would expect 1111(base 2) to convert to 15(base 10).
Comment 1 Conrad Meyer freebsd_committer 2017-08-29 14:58:35 UTC
Note that as soon as you set ibase=2, numbers are input in base r2.  obase=10 assigns 0b10 (== decimal 2) to obase.  You want obase=1010, or assign obase before changing ibase.  I believe this is identical in GNU bc.

$ bc  (GNU)
bc 1.06
Copyright 1991-1994, 1997, 1998, 2000 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
ibase=2
obase=1010
1111
15

$ /usr/bin/bc   (BSD)
ibase=2
obase=1010
1111
15