Home » Computer Programming
C/C++ hex string to integer
How can i conver a Hex String to Integer in C++?
By kingk (art. no 19)Hex String to Integer C/C++
How to convert a C/C++ hex string to integer?There are no standard ansi functions to perform the data conversion from a hex string to integer.
The atoh function here listed can easily convert an Hex String to Integer.
int atoh(char * string, int size, bool reverse)
{
//By www.oldwildweb.com
unsigned int value = 0;
int char_val = 0;
int hchar_val = 1;
if (reverse == true)
for (int i = 0; i < size; i++)
{
if (string[i] == '0')
char_val = 0;
if (string[i] == '1')
char_val = 1;
if (string[i] == '2')
char_val = 2;
if (string[i] == '3')
char_val = 3;
if (string[i] == '4')
char_val = 4;
if (string[i] == '5')
char_val = 5;
if (string[i] == '6')
char_val = 6;
if (string[i] == '7')
char_val = 7;
if (string[i] == '8')
char_val = 8;
if (string[i] == '9')
char_val = 9;
if (string[i] == 'a' || string[i] == 'A' )
char_val = 10;
if (string[i] == 'b' || string[i] == 'B' )
char_val = 11;
if (string[i] == 'c' || string[i] == 'C' )
char_val = 12;
if (string[i] == 'd' || string[i] == 'D' )
char_val = 13;
if (string[i] == 'e' || string[i] == 'E' )
char_val = 14;
if (string[i] == 'f' || string[i] == 'F' )
char_val = 15;
value = value + (hchar_val*char_val);
hchar_val *= 16;
}
else
for (int i = size-1; i >= 0; i--)
{
if (string[i] == '0')
char_val = 0;
if (string[i] == '1')
char_val = 1;
if (string[i] == '2')
char_val = 2;
if (string[i] == '3')
char_val = 3;
if (string[i] == '4')
char_val = 4;
if (string[i] == '5')
char_val = 5;
if (string[i] == '6')
char_val = 6;
if (string[i] == '7')
char_val = 7;
if (string[i] == '8')
char_val = 8;
if (string[i] == '9')
char_val = 9;
if (string[i] == 'a' || string[i] == 'A' )
char_val = 10;
if (string[i] == 'b' || string[i] == 'B' )
char_val = 11;
if (string[i] == 'c' || string[i] == 'C' )
char_val = 12;
if (string[i] == 'd' || string[i] == 'D' )
char_val = 13;
if (string[i] == 'e' || string[i] == 'E' )
char_val = 14;
if (string[i] == 'f' || string[i] == 'F' )
char_val = 15;
value = value + (hchar_val*char_val);
hchar_val *= 16;
}
return value;
}
Usage example:
atoh("F0",2, true);
//Output: 240
Php max get length
Apache and Php max get lenght
By kingk (art. no 16)Php max get length - Apache max Get Lenght
The max lenght of a GET variable is setted to 512 Bytes/Variable by default in all Php 5.x versions, while most browsers can support huge urls (with more than 2048 bytes depending on the browser version).To change the max get lenght parameter you can edit the related configuration file of Php5 under:
/etc/php5/apache2/conf.d/suhosin.ini
The lenght parameter is definited by the string:
suhosin.get.max_value_length = 512
The standard http url size is at least 8096 bytes, but most servers can use more.
Tags: Apache max Get Lenght - Php max get length - Max GET Lenght - Max Url Lenght
Warning session_start(): cannot send session cookie headers already sent by output started at
Common PHP errors
By kingk (art. no 15)Warning session_start(): cannot send session cookie headers already sent by output started at ...
This is one of the most common Warnings with CMS installations.Troubleshooting:
Check for those possible issues:
-File format (use always unix format with UTF-8 encode, choose those options with your favorite text editor)
-Do not leave blank space or chars before the ?php tag
-Don't use the ASCII file transfer mode with your FTP client, use the Binary mode instead.
Multi-Client socket server example in C
Easy socket server example in C
By kingk (art. no 11)Easy Multi client socket server in C
In this article we have posted a very easy example of how to make a multi client socket server in C.
This software uses an array of no blocking sockets and a loop to manage connected clients.
The code is very simple to understand so we avoid to put comments on it
Multi Client Socket Server in CTags: Socket Client C - Multi Client Socket Programming C - Socket Programming C - Socket Server Programming C - A multi client socket server application example - Socket Server Linux - Socket Server Unix - Multi Client Server Unix Example - Socket Server Example Linux - Socket Server Programmin C - Multi Client C socket server Example - No blocking socket programming C - No blocking socket server example in C - No blocking Multi Client Socket server in C
Kill processes in C# .NET
A simple function to kill a proces by name in C# .NET
By kingk (art. no 10)With this simple function we can search for active processes and kill them in C# .net.
Usage: FindAndKillProcess("processname");
For example to kill the windows calc application it whould be:
FindAndKillProcess("calc");
//Required parameters:
using System.Diagnostics;
using System.ServiceProcess;
//Function code
public void FindAndKillProcess(string name)
{
Process[] processes = Process.GetProcessesByName(name);
foreach (Process proc in processes)
{
proc.Kill();
}
}
A Java Modbus server on TCP/IP example
Multi-client multi-thread Java Modbus Server on TCP IP example by Ugo Cirmignani
By kingk (art. no 8)The Modbus is a simple and free industrial protocol, there is an official (and very good) documentation about the protocol but there are no so many examples of how implement a Modbus server on tcp/ip.
In this article we provide a simple class to create a Java Modbus server on TCP/IP capable to use the Read Holding Register function.
The "Read Inputs Register" function can be used to read data from a Modbus server with a Modbus client, each register is composed of 2 bytes of data (by standard each register is a 16bit integer).
To use the class consider this example:
package simpleserver;
public class Main
{
public static void main (String args[])
{
try
{
ModbusServer mbs = new ModbusServer(502);
Thread t = new Thread (mbs);
t.start();
while (true)
{
System.out.println("The server is running..");
Thread.currentThread().sleep(10000);//sleep for 1000 ms
}
}
catch (Exception ex)
{
}
}
}
Java Modbus serverHtml select with all usa cities
List of all usa cities in a html select form component
By kingk (art. no 6)Here's an html select with the list of all usa cities ordered by name.
HTML SELECT WITH ALL USA CITIESTags: All USA Cities - Html form with all usa cities
LZW implementation in C/C++ By Ugo Cirmignani
A good LZW algorithm implementation
By kingk (art. no 5)Here's a good LZW implementation in C/C++.
Author: Ugo Cirmignani
LZW Implementation C/C++Tags: An efficient LZW implementation - LZW Implementation in c
A Cryptography algoritm in Javascript and Php
A cheap and easy mode to encrypt databases and strings
By kingk (art. no 3)This project includes 2 cryptography library one in Php and one Javascript. The Cryptography algoritm is strong and not spreaded, so can be considered safe.
The Javascript library can be used to encrypt data in web forms before send anything in internet, and the php library allow the server to decrypt and elaborate the sent data.
This project could be a cheap alternative to a ssl connection.
There are just few function in those library (in Javascript/Php), functions are:
-To encrypt a string
String = X_Crypt_String(String, Password, true ) / $String = X_Crypt_String($String ,$Password, true )
-To decrypt a string
String = X_DeCrypt_String(String, Password, true ) / $String = X_DeCrypt_String($String, $Password, true )
Booleans agruments are used to specify if the base64 algoritm must be used after the encrypt function.
By Ugo Cirmignani
Crypter Javascript / Php Copyright 2009
