Plaster
New
List
Login
text
apl
aspx
asterisk
brainfuck
c
c++hdr
c++src
cassandra
ceylon
clojure
clojurescript
cmake
cobol
coffeescript
common-lisp
crystal
csharp
css
cypher-query
cython
d
dart
diff
django
dockerfile
dylan
ebnf
ecl
ecmascript
edn
eiffel
ejs
elm
erb
erlang
ez80
factor
fcl
feature
forth
fortran
fragment
gfm
go
gql
groovy
gss
haml
handlebars-template
haskell
haxe
hive
html
http
httpd-php
httpd-php-open
hxml
ini
java
javascript
json
jsp
jsx
julia
kotlin
latex
less
literate-haskell
lua
mariadb
markdown
mbox
mirc
mscgen
msgenny
mssql
mumps
mysql
n-triples
nesc
nginx-conf
nsis
objectivec
octave
oz
pascal
perl
pgp
pgp-keys
pgp-signature
pgsql
php
pig
plsql
properties
protobuf
puppet
python
q
rpm-changes
rpm-spec
rsrc
ruby
rustsrc
sas
sass
scala
scheme
scss
sieve
slim
smarty
solr
soy
sparql-query
spreadsheet
sql
squirrel
stex
styl
swift
systemverilog
tcl
textile
tiddlywiki
tiki
tlv
tornado
ttcn-asn
ttcn-cfg
turtle
twig
typescript
typescript-jsx
vb
vbscript
velocity
verilog
vertex
vhdl
vue
webidl
xml
xml-dtd
xquery
xu
yaml
z80
default
Visibility:
public
unlisted
private
(defun bytes-to-int (array) (let ((arr-len (length array))) (when (< 4 (length array)) (error "can't make a 32bit integer from more than 4 8bit bytes")) (cond ((= arr-len 1) (aref array 0)) ((= arr-len 2) (logior (ash (aref array 0) 8) (aref array 1))) ((= arr-len 3) (logior (ash (aref array 0) 16) (ash (aref array 1) 8) (aref array 2))) ((= arr-len 4) (logior (ash (aref array 0) 24) (ash (aref array 1) 16) (ash (aref array 2) 8) (aref array 3)))))) (defun strip-trailing-0s (array) "Removes only 0's on the end of a sequence, it will skip 0's in the middle and returns a new sequence" (loop :for x :across (reverse array) :for i :downfrom (length array) :to 0 :unless (zerop x) :return (subseq array 0 i)))) ;;;;; NET-CONSTRUCT> (bytes-to-int #(1 0 0 0)) 16777216 (25 bits, #x1000000) NET-CONSTRUCT> (bytes-to-int (strip-trailing-0s #(1 0 0 0))) 1 (1 bit, #x1, #o1, #b1) ;value I want NET-CONSTRUCT> (bytes-to-int (strip-trailing-0s #(48 57 0 0))) 12345 (14 bits, #x3039) ;value I want NET-CONSTRUCT> (bytes-to-int #(48 57 0 0)) 809041920 (30 bits, #x30390000)