Skip to content

Instantly share code, notes, and snippets.

View SIRHAMY's full-sized avatar
🐷
Loading...

Hamilton Greene SIRHAMY

🐷
Loading...
View GitHub Profile
@GET
@Path("/getMyInfoXML")
@Produces("application/xml")
public String getMyInfoXML(@QueryParam("name") String name)
{
StringBuilder sb = new StringBuilder();
String firstName = name;
String lastName = "Greene";
@SIRHAMY
SIRHAMY / Dec Int to Hex String
Last active August 29, 2015 13:56
Converts a base 10 integer to a hexadecimal string of ASCII characters.
public static String itostrx(int hex)
{
String result = "";
String[] hexes = {"0", "1", "2", "3", "4","5","6","7","8","9","A",
"B","C","D","E","F"};
while(hex >= 0){
if(hex < 16){
result = hexes[hex] + result;
break;
@SIRHAMY
SIRHAMY / Integer to Binary String of ASCII Characters
Created February 6, 2014 04:24
Converts an integer to a String of binary in ASCII characters
public static String itostrb(int binary)
{
String result = "0";
int scalar = 1;
int placeHolder = 1;
while(binary>0){
if((binary - scalar*2)>=0){
scalar*=2;
placeHolder++;
}else{
@SIRHAMY
SIRHAMY / String Hexadecimal to int
Created January 26, 2014 02:25
Converts a string of hexadecimal ASCII characters to the int primitive data type
public static int strxtoi(String hex)
{
int result = 0;
for(int i = 0; i<hex.length();i++)
{
int scalar = 0;
if(hex.charAt(i)>57)
{
scalar = hex.charAt(i) - 55;
}
@SIRHAMY
SIRHAMY / Convert ASCII Binary string to decimal int
Created January 26, 2014 01:28
Converts a string of binary in ASCII characters to decimal in the form of the integer primitive data type.
public static int strbtoi(String binary)
{
int result = 0;
for(int i = 0; i<binary.length() ; i++){
if(binary.charAt(i)==49){
if(i==binary.length()-1){
result += 1;
}else{
int scalar = 2;
for(int j = i + 1; j < binary.length()-1;j++){
@SIRHAMY
SIRHAMY / String int to int
Created January 26, 2014 00:21
Method that converts given string of positive integers into the integer primitive data type.
public static int strdtoi(String decimal)
{
int scalar = 1;
int result = 0;
for(int i=decimal.length()-1;i>=0;i--){
result += (decimal.charAt(i) - 48) * scalar;
scalar*=10;
}
return result;
}
@SIRHAMY
SIRHAMY / switchActivityExample
Created November 19, 2013 19:53
Example Java code demoing how to give a button the functionality to switch between activities.
public class ExampleActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Tells Android which XML file holds this class' information
setContentView(R.layout.ExampleActivityXMLFile);
//Sets up the chosen button
Button demo = (Button) findViewById(R.id.exampleButton);