본문 바로가기
반응형

코드보관소12

[python] 2진수 비트를 뒤집는 방법 def reverse_bits(n): bin_str = bin(n)[2:] # 2진수 문자열 생성 후 접두사 제거 reversed_bin_str = bin_str[::-1] # 2진수 문자열 뒤집기 return int(reversed_bin_str, 2) # 뒤집힌 2진수 문자열을 10진수로 변환 bit = 0b10001000 # 뒤집을 2진수 정수값 reverse = reverse_bits(bit) print(bin(reverse)) # 뒤집힌 2진수 출력 (접두사 "0b"는 이진수임을 나타냄) # 결과 : 0b100001 2023. 5. 11.
[python] CRC-16 msb fast , lsb fast 생성 함수 # CRC-16 LSB 우선 타입 코드 생성 함수 def crc16_lsb_fast(data, poly, init): polynomial = poly crc = init for byte in data: crc = crc ^ (byte >= 1 return crc # "ABCD" 문자열에 대한 CRC 계산 예시 data = b'ABCD' crc16_xmodem = crc16_lsb_fast(data, 0x1021, 0x0000) crc16_modbus = crc16_msb_fast(data, 0x8005, 0xFFFF) # 계산된 CRC 값을 16진수로 출력 print(hex(crc16_xmodem)) # 결과 : 0x3b3a print(hex(crc16_modbus)) # 결과 : 0xf85 2023. 5. 11.
파이스크립트 테스트 HTML 삽입 미리보기할 수 없는 소스 https://itadventure.tistory.com/537 2022. 7. 3.
키보드를 반복해서 누르는 방법 -- 시간 설정 function setClock() return os.clock() end -- 경과 시간 function getClock(clock) return os.clock() - clock end -- XX연타 GO_CYCLE_TIME = 3 -- 이동키 연타를 할 사이클 설정 (단위:초) if xx == nil then xx = setClock() elseif getClock(xx) > GO_CYCLE_TIME then Keybd('') Keybd('') print('이동! GoGoGo! ') xx = nil end -- 스킬 사용 SKILL_CYCLE_TIME = 2 -- 스킬 사용후 다음 스킬 사용할 시간 설정 (단위:초) SKILL_REST_TIME = 5 -- 스킬 모두 사용후 재시작 .. 2022. 4. 27.
[lua] 함수를 실행하는 함수 function start(func, ...) func(...) end start(print, 'hello, world!') -- 'hello, world!' 2022. 3. 22.
[lua] string replace a = '[PLC1]X01234' print(a) -- > [PLC1]X01234 a = a:gsub('%[PLC1]','') print(a) -- > X01234 a = a:gsub('%Y0', 'Y') a = a:gsub('%X0', 'X') a = a:gsub('%M0', 'M') print(a) -- > X1234 2022. 3. 18.
[JavaScript] Hello, World! " data-ke-type="html">HTML 삽입미리보기할 수 없는 소스  텍스트 윈도우 박스 생성Hello World! 버튼" data-ke-type="html">HTML 삽입미리보기할 수 없는 소스   텍스트 변경 버튼아래 버튼을 누르세요Text Change 버튼" data-ke-type="html">HTML 삽입미리보기할 수 없는 소스   시간정보 불러오기현재 날짜와 시간 표시하기!date" data-ke-type="html">HTML 삽입미리보기할 수 없는 소스 2021. 8. 28.
[pyqt] pyinstaller .ui 포일 포함시키기 # PySide 를 사용하는 경우 import os import sys from PySide6.QtWidgets import * from PySide6.QtCore import Qt from PySide6 import QtUiTools # pyinstaller .ui 파일 포함 def resource_path(relative_path): """ Get absolute path to resource, works for dev and for PyInstaller """ base_path = getattr(sys, '_MEIPASS', os.path.dirname(os.path.abspath(__file__))) return os.path.join(base_path, relative_path) form = r.. 2021. 7. 30.
[win32api] WM_MESSAGE CONSTANCE # Generated by h2py from commdlg.h (plus modifications 4jan98) WINVER = 1280 WM_USER = 1024 PY_0U = 0 OFN_READONLY = 1 OFN_OVERWRITEPROMPT = 2 OFN_HIDEREADONLY = 4 OFN_NOCHANGEDIR = 8 OFN_SHOWHELP = 16 OFN_ENABLEHOOK = 32 OFN_ENABLETEMPLATE = 64 OFN_ENABLETEMPLATEHANDLE = 128 OFN_NOVALIDATE = 256 OFN_ALLOWMULTISELECT = 512 OFN_EXTENSIONDIFFERENT = 1024 OFN_PATHMUSTEXIST = 2048 OFN_FILEMUSTEXIST .. 2021. 7. 20.
[lua] file --file open -- r : Read only -- w : overwrite or create a new file -- a : Append or create a new file -- r+ : Read & Write existing file -- w+ : Overwrite read or create a file -- a+ : Append read or create file file = assert(io.open("test.txt", "w")) file:write("Hello World") file:close() -- http://lua-users.org/wiki/FileInputOutput -- see if the file exists function file_exists(file) local f =.. 2021. 7. 13.
[lua] hello, world! function hello() print('Hello, World!') end hello() -- 'hello, world!' 2021. 7. 12.
[python] hello, world! def hello(): print('hello, world!') if __name__ == '__main__': hello() # 'hello, world!' 2021. 5. 2.
반응형