npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

bin-to-hex

v0.4.1

Published

Convert BIN data to HEX string

Downloads

58

Readme

BIN to HEX converter

Converts a bin array to an (Intel) HEX string. More specifically I8HEX since only record types 00 and 01 are being used.

Usage

Can be used in both nodeJs and Browser context, you only need to supply the binary data in form of a Uint8Array:

import BinToHex from "bin-to-hex";

const data = new Uint8Array([0xDE, 0xAD, 0xBE, 0xEF]);
const converter = new BinToHex();
const hex = converter.convert(data);

console.log(hex)

Alternatively you can pass configuration to the consturctur, the following values are assumed to be the defaults if you do not instantiate with parameters:

import BinToHex from "bin-to-hex";

const maxBytes = 10;
const offset = 0;
const empty = null;
const converter = new BinToHex(maxBytes, offset, empty);

Those parameters additionally have setters and getters:

converter.setMaxBytes(4);
converter.getMaxBytes();
  • maxBytes: The maximum amount of data bytes per record
  • offset: Offset for the address in case the data should not start at 0x00
  • empty: If empty value is set, bytes with this value will be removed from the resulting HEX. If the flash hast the value 0xFF after bein erased, the hex file does not need to include those segments of memory, reducing the overall file size of the HEX file.

You can provide the binary data to the convert methods in different ways, for example by reading a local file or converting a Blob to a Buffer.

HEX format

Each line in a HEX file represents a chunk of data at a specific address:

:{RCLEN}{ADDRESS}{RECTYPE}{DATA}{CHECKSUM}
  • :: Startcode
  • RCLEN: Length of {DATA} in bytes
  • ADDRESS: The address of the data (16 Bit)
  • RECTYPE: Record type - this can either be 00 (Data) or 01 (End of file)
  • DATA: {RCLEN} amount of data bytes
  • CHECKSUM: Checksum over the whole record ({ADDRESS}, {RECTYPE} and {DATA})

Every HEX file ends with a 01 (End of file) record.

The binary representation of 0xDEADBEEF would end up in the following HEX file representation:

:04 0000 00 DEADBEEF

Development

yarn install

Run linter

yarn lint

Run tests

yarn test

Build for NPM

yarn build

Publish to NPM

Lint, test and build

yarn pre-publish

and finally publish to NPM

yarn publish

Using locally

In order to use the library locally it needs to be linked like so:

  1. In the root directory of this library run: yarn link
  2. Make sure a build exists yarn build
  3. In the root directory where you want to use this library run yarn link "bin-to-hex"

Then you can import and use the library:

import BinToHex from 'bin-to-hex';

const data = new Uint8Array([0xDE, 0xAD, 0xBE, 0xEF]);
const converter = new BinToHex();
const hex = converter.convert(data);

console.log(hex);

Contributing

Contributions are very welcome, please direct your PRs against the develop branch.