{"id":13442695,"url":"https://github.com/thephoeron/bit-smasher","last_synced_at":"2026-01-10T12:01:36.408Z","repository":{"id":142776493,"uuid":"21108553","full_name":"thephoeron/bit-smasher","owner":"thephoeron","description":"Common Lisp library for handling bit vectors, bit vector arithmetic, and type conversions.","archived":false,"fork":false,"pushed_at":"2022-07-08T04:10:07.000Z","size":63,"stargazers_count":53,"open_issues_count":6,"forks_count":6,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-10-28T05:59:38.156Z","etag":null,"topics":["binary","binary-arithmetic","bit-vector","common-lisp","type-conversion","unsigned-integers"],"latest_commit_sha":null,"homepage":"https://thephoeron.github.io/bit-smasher/","language":"Common Lisp","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/thephoeron.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2014-06-22T23:27:00.000Z","updated_at":"2024-09-22T12:47:49.000Z","dependencies_parsed_at":"2023-04-27T00:04:01.671Z","dependency_job_id":null,"html_url":"https://github.com/thephoeron/bit-smasher","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thephoeron%2Fbit-smasher","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thephoeron%2Fbit-smasher/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thephoeron%2Fbit-smasher/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thephoeron%2Fbit-smasher/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thephoeron","download_url":"https://codeload.github.com/thephoeron/bit-smasher/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244639825,"owners_count":20485934,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["binary","binary-arithmetic","bit-vector","common-lisp","type-conversion","unsigned-integers"],"created_at":"2024-07-31T03:01:49.277Z","updated_at":"2026-01-10T12:01:31.073Z","avatar_url":"https://github.com/thephoeron.png","language":"Common Lisp","funding_links":[],"categories":["Common Lisp","Expert Systems"],"sub_categories":[],"readme":"# BIT-SMASHER\n\n[![Quicklisp](https://quickdocs.org/badge/bit-smasher.svg)](https://quickdocs.org/bit-smasher/)\n[![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE)\n\nCommon Lisp library for handling bit vectors, bit vector arithmetic, and type conversions.\n\nAvailable in Quicklisp as of July 2014 release.\n\nDocumentation available at: https://thephoeron.common-lisp.dev/bit-smasher/\n\n### Supported Platforms\n\nThe current release of BIT-SMASHER *compiles without warning* and passes all\ntests on 64-bit versions of the following Lisp implementations:\n\n- SBCL 2.2.5\n- Clozure CL 1.12.1\n- CLISP 2.49.92\n- ABCL 1.9.0\n- Allegro CL 10.1\n\nIt *compiles with warnings* on:\n\n- LispWorks 8.0.1\n\nIt *compiles with style-warnings* on:\n\n- ECL 21.2.1\n\nIt *does not build* on:\n\n- CLASP CL 1.0.0 (clasp-boehmprecise-1.0.0-316-gf3b9992a5)\n- CMUCL 21d\n\n### Usage Notes and Limitations\n\nThis library was designed to complement the set of functions included in the\nCommon Lisp specification for handling bit-vectors, by adding relevant lookup,\nconversion, arithmetic, measurement, and predicate functions.  For documentation\nand tutorials on the bit-vector functions included in the Common Lisp standard,\nplease refer to:\n\n* Common Lisp HyperSpec:\n    * [accessor BIT, SBIT](http://www.lispworks.com/documentation/lw50/CLHS/Body/f_bt_sb.htm)\n    * [function BIT-AND, etc...](http://www.lispworks.com/documentation/lw50/CLHS/Body/f_bt_and.htm)\n    * [function BIT-VECTOR-P](http://www.lispworks.com/documentation/lw50/CLHS/Body/f_bt_vec.htm)\n* Successful Lisp: [Chapter 18](http://psg.com/~dlamkins/sl/chapter18.html)\n\nBIT-SMASHER only handles the set of non-negative integers.  As such, arithmetic\non bit-vectors may not always produce the results you expect\u0026mdash;return values\nof all arithmetic functions are given as the bit-vector of the absolute ceiling\nvalue. Manual conversion of negative integers, floats, fractions, or complex\nnumbers will trigger an error.\n\n### Examples\n\nThe conversion functions allow you to convert universally between bit-vectors,\noctet-vectors, hexadecimal strings, and non-negative integers.\n\n```lisp\n; universal type-casting style functions\n(bits\u003c- \"F0\") =\u003e #*11110000\n(bits\u003c- 240) =\u003e #*11110000\n(int\u003c- #*11110000) =\u003e 240\n\n; manual conversions without type-checking\n(hex-\u003ebits \"F0\") =\u003e #*11110000\n(int-\u003ebits 10) =\u003e #*00001010\n(octets-\u003ebits (int-\u003eoctets 244)) =\u003e #*11110100\n; etc., etc...\n```\n\nBit-vectors are returned zero-padded to the next full byte.\n\n```lisp\n(bits\u003c- 255) =\u003e #*11111111\n(bits\u003c- 256) =\u003e #*0000000100000000\n```\n\nArithmetic on bit-vectors can be achieved through the functions `bit-sum`,\n`bit-difference`, `bit-product`, `bit-quotient`, `bit-floor`, `bit-ceiling`,\n`lshift`, and `rshift`.  There are also the shorthand macros, `bit+`, `bit-`,\n`bit*`, `bit/`, `\u003c\u003c`, and `\u003e\u003e`.  As stated above, the bit-vector arithmetic\nfunctions return the absolute ceiling value of the operation.  So,\n\n```lisp\n(bit- #*0000 #*0010) =\u003e #*00000010 ; +2, not -2\n```\n\nThe measurement functions `wide-bit-length` and `min-bit-length` tell you the\nmaximum and minimum number of bits needed to store a value, respectively.  They\noperate on bit-vectors, octet-vectors, hexadecimal strings, and non-negative\nintegers.\n\n```lisp\n(wide-bit-length 256) =\u003e 16\n(min-bit-length 256) =\u003e 9\n```\n\nThere is also the measurement function `byte-length` that returns the total\nnumber of bytes required to store an integer, bit-vector, or hexadecimal value;\nor the actual length of byte vector or simple byte array.\n\n```lisp\n(byte-length \"A0FF\") =\u003e 2\n(byte-length 65536) =\u003e 3\n```\n\nIn addition to the built-in CL predicate function, `bit-vector-p`, BIT-SMASHER\nadds the predicate function `twos-complement-p`, when you need to test the\nminimum bit length for the two's complement rule. This is required where padding\nbit-vectors, octet-vectors, or hex-strings with leading zeros up to a set\nword-length is expected.\n\n```lisp\n(twos-complement-p 256) =\u003e NIL\n(twos-complement-p 255) =\u003e T\n```\n\n### License\n\nCopyright \u0026copy; 2014\u0026ndash;2022, \"the Phoeron\" Colin J.E. Lupton and the\nContributors. This project is released under the MIT License; please see\n[bit-smasher/LICENSE](./LICENSE) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthephoeron%2Fbit-smasher","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthephoeron%2Fbit-smasher","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthephoeron%2Fbit-smasher/lists"}