RhinoDevel

Software development projects and more.

Archive for the ‘Development’ Category

JavaScript: Convert number to binary (string)

with 2 comments

Create a string holding the binary representation of a number (that is initially converted to a positive integer) with JavaScript:

var decToBinStr = function(n)
{
    var s, i;

    if(n===0.0)
    {
        return String(0);
    }

    i = ~~Math.abs(n); // Positive integer wanted.
    s = '';
    do
    {
        s = i%2 + s;
        i = ~~(i/2); // Integer division.
    }while(i>0);
    return s;
};

The function above creates the binary representation as one would do it with pen and paper.

I implemented it this way to show how you can do it in any programming language.

But if you are interested in a “better” way to do this with JavaScript:

You may also use the >>> (zero-fill right shift) operator to achieve this (or something almost similar..) with less code. See Mozilla and stackoverflow.com.

Advertisements

Written by RhinoDevel

27. June 2017 at 11:03

Posted in Development, JavaScript

Tagged with ,

Atom cheat sheet

leave a comment »

I recommend the open source Atom editor – especially for software developers.

Here comes my Atom cheat sheet that should be useful for everybody who is already accustomed to standard text editor controls, but starts using Atom (the shortcuts may be a little bit different, if you are not using Windows, but Linux or MacOS):

CTRL+SHIFT+P = Command Palette

CTRL+T = Fuzzy Finder

CTRL+B = Fuzzy Finder in buffers.

CTRL+, = Settings View

CTRL+TAB / CTRL+SHIFT+TAB = Cycle through panes.
CTRL+K -> UP/DOWN/LEFT/RIGHT = Split panes in some direction.
CTRL+K -> CTRL+UP/DOWN/LEFT/RIGHT = Move through panes in some direction.

CTRL+W = Close pane item (tab) / empty pane / window.

CTRL+LEFT = To beginning of word.
CTRL+RIGHT = To end of word.
CTRL+HOME = To top of file.
CTRL+END = To end of file.
CTRL+G = Move to row (and column).
CTRL+R = Move to a symbol in current file (e.g. a method definition).
CTRL+M = Jump to the bracket matching the one adjacent to the cursor.
It jumps to the nearest enclosing bracket when there's no adjacent bracket.

CTRL+ALT+F2 = Set/unset bookmark at current line.
F2 / SHIFT+F2 = Cycle forwards and backwards through bookmarks in current file.
CTRL+F2 = Move to a bookmark in project.

CTRL+SHIFT+LEFT = Select to beginning of word.
CTRL+SHIFT+RIGHT = Select to end of word.
CTRL+L = Select entire line.
CTRL+ALT+M = Select all the text inside the current brackets.

CTRL+J = Join the next line to the end of the current line.
CTRL+UP / CTRL+DOWN = Move the current line up or down.
CTRL+SHIFT+D = Duplicate current line.
CTRL+SHIFT+K = Delete current line.
CTRL+BACKSPACE = Delete to beginning of word.
CTRL+DEL = Delete to end of word.

The original source for all the shortcuts above is the Atom Flight Manual.

Written by RhinoDevel

21. October 2016 at 16:34

Posted in Development

Tagged with

MTRovio – C++ source code to help communicating with Rovio

MTRovio is C++ source code I wrote to help communicating with the WowWee Rovio mobile IP camera.

It might be useful in your own Rovio projects!

I hope the source code is pretty self-explanatory. 🙂

Download it right here:

https://docs.google.com/file/d/0B6suboZCKq0LTzNxRTJ2TEFvZFE/edit

Have fun! 🙂

Written by RhinoDevel

13. January 2013 at 11:22

Posted in Development

Tagged with , , ,

%d bloggers like this: