Showing posts with label binary and decimal conversion. Show all posts
Showing posts with label binary and decimal conversion. Show all posts

Sunday, January 26, 2014

TI-84+: BIN2DEC, DEC2BIN, DRAWICON

TI-84+: BIN2DEC, DEC2BIN, DRAWICON

Switching gears for a bit, this blog focuses on the TI-84+:

BIN2DEC: Binary to Decimal: Now allows for any size (up to memory limit).
Input: A list of bits (zeroes and ones). Power of 2 is in descending order from 2^(D-1) to 2^0 where D is the length of the list.

L1: List 1 (2nd, 1; shown as big L with 1 as a subscript)

Example: 11011_2 → 27_10
Input (L1): {1,1,0,1,1}
Output (N): 27

PROGRAM:BIN2DEC
: Input "L1 OF 0 AND 1S:",L1
: dim(L1)→D
: 0→N
: For(K,0,D-1)
: N+2^K*L1(D-K)→N
: End
: Disp "N=DEC"
: Disp N


DEC2BIN: Decimal to Binary
Input: Integer (anything after the decimal point is ignored)
Output: List of binary bits. Power of 2 is in descending order from 2^(D-1) to 2^0 where D is the length of the list.

Example: 5427_10 → 1010100110011_2
Input (N): 5427
Output (L1): {1,0,1,0,1,0,0,1,1,0,0,1,1}

PROGRAM:DEC2BIN
: Input "N:", N
: If N<0
: Then
: Disp "INVALID"
: Stop
: End
: iPart(N)→M
: iPart(ln(M)/ln(2))+1→D
: DelVar L1
: D→dim(L1)
: For(K,0,D-1)
: If 2^(D-1-K)≤M
: Then
: 1→L1(K+1)
: M-2^(D-1-K)→M
: End
: End
: Disp "L1=BIN"
: Pause L1


DRAWICON: Draws a 5 × 5 pixelated pictures using an integer from 1 to 33,554,431. The number is converted into its binary bits. The upper left hand corner represents 2^24. The exponent decreases going right then down each row, with 2^0 representing the bottom right hand corner.

Matrix:

PROGRAM:DRAWICON
: 24→N
: Input "NUMBER < 2^25:", M
: If M>2^25-1
: Then
: Disp "EXCESS"
: Stop
: End
: iPart(M)→M
: ClrHome
: For(R,1,5)
: For(C,1,5)
: If 2^N≤M
: Then
: Output(R,C,"X")
: M-2^N→M
: End
: N-1→N
: End
: End
: Pause
: ClrHome


Below are a few examples:

Enjoy, and don't forget to make each day count! Until next time,

Eddie


This blog is property of Edward Shore. 2014


Wednesday, February 20, 2013

TI-84+: Binary-Decimal Conversions

One of the missing features of the TI-82/83/84 family is the ability to convert between bases. Here are two programs in TI-Basic to help fill at least some of the gap.

It is very basic conversion, working only with positive integers up to 65,535 (16 ones as its binary representation).

Variables used:
N = number in decimal form
L1 = list representing the binary representation (1s and 0s)

The programs display the binary numbers as a solid number, rather by a list. This is accomplished by a For loop involving the Output command.

Access L1 by pressing [2nd], [ 1 ].

Examples: Decimal ← → Binary
27 ← → {0,0,0,0,0,0,0,0,0,0,0,1,1,0,1,1}
428 ← → {0,0,0,0,0,0,0,1,1,0,1,0,1,1,0,0}
3,245 ← → {0,0,0,0,1,1,0,0,1,0,1,0,1,1,0,1}

DEC2BIN
Decimal to Binary (N → L1)
This program works with any positive integer from 0 to 65,535 - 16 bits. No negative numbers. Note: ending quotes and parenthesis are left out to conserve space.
2/20/2013. 170 bytes.  (updated 7/5/2016)

: Input "N:",N
: If N<0 

: Then
: Pause "INVALID
: Stop
: End
: int(N→N
: N→D
: DelVar L1
: 16→dim(L1
: For(K,0,15
: If 2^(15-K)≤D
: Then
: 1→L1(K+1
: D-2^(15-K→D
: End
: End
: ClrHome
: Output(1,1,N
: Output(1,6,">BIN
: For(K,1,16
: Output(3,K,L1(K
: End
: Pause
: ClrHome


BIN2DEC
Binary to Decimal (L1 → N). Enter a list up to 16 zeroes and ones.
This program works with any positive integer from 0 to 65,535 - 16 bits. No negative numbers. Note: ending quotes and parenthesis are left out to conserve space.
2/20/2013. 160 bytes.


: Input "L1 UP TO 16 BITS:",L1
: If dim(L1)>16
: Then
: Pause "INVALID
: Stop
: End
: While dim(L1) < 16

: augment({0},L1→L1
: End
: 0→N
: For(K,0,15
: N+2^K*L1(16-K→N
: End
: ClrHome
: For(K,1,16
: Output(1,K,L1(K
: End
: Output(3,1,">DEC
: Output(3,6,N
: Pause
: ClrHome


** Edited 12/5/2013.  This is due to an error Stephanie Ison pointed out to me.  Many thanks! - Eddie 

Enjoy!

Eddie


This blog is property of Edward Shore. 2013




RPN HP 12C: Fibonacci and Lucas Sequences

  RPN HP 12C: Fibonacci and Lucas Sequences Golden Ratio, Formulas, and Sequences Let φ be the Golden Ratio: φ = (1 + √5) ÷ 2...