Skip to content

Instantly share code, notes, and snippets.

View astkaasa's full-sized avatar
🎯
Focusing

astkaasa

🎯
Focusing
View GitHub Profile
@astkaasa
astkaasa / gist:5392781
Created April 16, 2013 02:01
problem 5.5
public class BitConvertNumbers {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println( bitSwapRequired( 1089, 7 ) );
}
@astkaasa
astkaasa / gist:5392785
Created April 16, 2013 02:03
problem 5.2
public class TestFloat {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
//System.out.println( "Please input a real number between 0 and 1, 0.72 for example:" );
@astkaasa
astkaasa / gist:5392789
Created April 16, 2013 02:04
problem 5.1
public class InsertBinary {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int n = 1089;
int m = 7;
int i = 2;
@astkaasa
astkaasa / gist:5392911
Last active December 16, 2015 06:39
problem 5.8
//assume x1 < x2
drawHorizontalLine( byte[] screen, int width, int x1, int x2, int y ) {
int start = y * width / 8 + ( int ) x1 / 8;
int end = y * width / 8 + ( int ) x2 / 8;
for ( int i = start; i <= end; i++ ) {
screen[ i ] = 127;
}
if ( start == end ) {
screen[ start ] = screen[ start ] >> ( x1 % 8 );
@astkaasa
astkaasa / gist:5406441
Created April 17, 2013 18:08
problem 1.5
import java.util.Scanner;
public class StringCompression {
private static Scanner in;
/**
* @param args
*/
public static void main(String[] args) {
@astkaasa
astkaasa / gist:5406571
Created April 17, 2013 18:27
problem 1.8
public static void main( String[] args ) {
String s11 = s1 + s1;
if ( isSubstring( s11, s2 ) )
System.out.println( "s2 is a rotation of s1.");
else
System.out.println( "s2 is not a rotation of s1." );
}
//check if s2 is a substring of s1
public static boolean isSubstring( String s1, String s2 ) {