Skip to content
Snippets Groups Projects
Commit e126be73 authored by Alexandros Asonitis's avatar Alexandros Asonitis
Browse files

Binary to Octal and Octal to Binary functions!

parent 194d360b
No related branches found
No related tags found
No related merge requests found
%% Cell type:code id:b3965c31-edec-4d04-856c-c4bb850bd22a tags:
``` python
import hp3497a_lib
```
%% Cell type:code id:2c7d107a-4035-48b6-8024-2fe5a438b1b7 tags:
%% Cell type:code id:a4f45391-ec6d-47c2-ae1e-445097197bdb tags:
``` python
daq = hp3497a_lib.hp3497a()
bin = hp3497a_lib.octal_to_bin(177777)
```
%% Cell type:code id:a4f45391-ec6d-47c2-ae1e-445097197bdb tags:
%% Cell type:code id:dad4cac4-c0fb-438a-8928-da8332701f2c tags:
``` python
print(bin)
```
%% Output
1111111111111111
%% Cell type:code id:73e839ca-fb78-47f4-8076-43676d6bb4ad tags:
``` python
octal = hp3497a_lib.bin_to_octal(bin)
print(octal)
```
%% Output
177777
%% Cell type:code id:b21fc931-38d2-492b-8b16-1703421366d3 tags:
``` python
```
......
......@@ -433,4 +433,17 @@ class hp3497a(object):
"""
self.inst.write(f"VW{n}")
# This to convert binary to octal and vise versa
def bin_to_octal(bin):
decimal = int(str(bin),2)
octal = format(decimal,'o')
return octal
def octal_to_bin(octal):
decimal = int(str(octal),8)
bin = format(decimal,'b')
return bin
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment