```python
%matplotlib inline
from IPython.display import display,Math
from sympy import *
init_session()
```

    IPython console for SymPy 1.7.1 (Python 3.8.5-64-bit) (ground types: gmpy)
    
    These commands were executed:
    >>> from __future__ import division
    >>> from sympy import *
    >>> x, y, z, t = symbols('x y z t')
    >>> k, m, n = symbols('k m n', integer=True)
    >>> f, g, h = symbols('f g h', cls=Function)
    >>> init_printing()
    
    Documentation can be found at https://docs.sympy.org/1.7.1/
    



```python
m = 231
m10 = m
(m,d) = (m//2,m%2)
print(m,d)
m2 = str(d)
while m>0:
    (m,d) = (m//2,m%2)
    print(m,d)
    m2 = str(d)+m2
print("{0:d}を2進法で表すと{1:s}".format(m10,m2))
```

    115 1
    57 1
    28 1
    14 0
    7 0
    3 1
    1 1
    0 1
    231を2進法で表すと11100111



```python
from ipywidgets import interact,Dropdown
basenumlist = [2,8,16]
basefunclist = [bin,oct,hex]
dd = Dropdown(
    options=[('2進法', 0), ('8進法', 1), ('16進法', 2)],
    value=0,
    description='進法:')
@interact
def _(n=(0,1000,1),dd=dd):
    basenum = basenumlist[dd]
    basefunc = basefunclist[dd]
    return display(Math("{0:4d} = {2:s}_{{ {1:d} }}".format(n,basenum,basefunc(n)[2:])))

```




    interactive(children=(IntSlider(value=500, description='n', max=1000), Dropdown(description='進法:', options=(('…




```python
from ipywidgets import interact
from ipywidgets import interact,Dropdown,IntSlider
@interact
def _(s="11111",m=IntSlider(value=2,min=2,max=16,step=1)):
    return display(Math("{0:s}_{{ {1:d} }}= {2:d}".format(s,m,int(s,m))))

```




    interactive(children=(Text(value='11111', description='s'), IntSlider(value=2, description='m', max=16, min=2)…




```python
from ipywidgets import interact
from ipywidgets import interact,Dropdown,IntSlider
D = 24
@interact
def _(n=IntSlider(value=0,min=0,max=2**D,step=1),d=IntSlider(value=1,min=1,max=D,step=1)):
    nb = bin(n)[2:]
    nb1 = nb[0:-d] # オーバーフロー分
    nb2 = nb[-d:]  # 残り
    n2 = bin(n%(2**d))[2:]
    n2len = len(str(n2))
    n2str = '0'*(d-n2len) + n2
    return display(Math("{0:d} = \\color{{red}}{{{1:s} }}\\color{{blue}}{{{2:s} }}_2\\rightarrow {3:s}_2 = {4:d} \quad({5:d}ビット)".format(n,nb1,nb2,n2str,n%(2**d),d)))
```




    interactive(children=(IntSlider(value=0, description='n', max=1024), IntSlider(value=1, description='d', max=1…




```python

```

f077c659d904ae3d53ae1ab18014b145501c03c0
ipynb
Jupyter Notebook
21jk1-0407.ipynb
ritsumei-aoi/21jk1
2d49628ef8721a507193a58aa1af4b31a60dfd8b
Apache-2.0
21jk1-0407.ipynb
ritsumei-aoi/21jk1
2d49628ef8721a507193a58aa1af4b31a60dfd8b
Apache-2.0
21jk1-0407.ipynb
ritsumei-aoi/21jk1
2d49628ef8721a507193a58aa1af4b31a60dfd8b
Apache-2.0
Qwen/Qwen-72B
1. YES
2. YES