Code covered by the BSD License  

Highlights from
NUMBER SYSTEMS/ BASE CONVERTER

image thumbnail

NUMBER SYSTEMS/ BASE CONVERTER

by

 

13 Aug 2006 (Updated )

Convert a number between different number systems-hex,oct,bin,dec.

num_sys(varargin)
function varargout = num_sys(varargin)

% GUI for number system converter.
gui_Singleton = 0;
gui_State = struct('gui_Name',       mfilename, ...
    'gui_Singleton',  gui_Singleton, ...
    'gui_OpeningFcn', @numsys_OpeningFcn, ...
    'gui_OutputFcn',  @numsys_OutputFcn, ...
    'gui_LayoutFcn',  [] , ...
    'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end

% --- Executes just before numsys is made visible.
function numsys_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
guidata(hObject, handles);
% --- Outputs from this function are returned to the command line.
function varargout = numsys_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;

% --- Executes on selection change in listbox_input.
function listbox_input_Callback(hObject, eventdata, handles)


% --- Executes during object creation, after setting all properties.
function listbox_input_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function editbox_input_Callback(hObject, eventdata, handles)
a=get(hObject,'String');

% --- Executes during object creation, after setting all properties.
function editbox_input_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

% --- Executes on selection change in listbox_output.
function listbox_output_Callback(hObject, eventdata, handles)

% --- Executes during object creation, after setting all properties.
function listbox_output_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function editbox_output_Callback(hObject, eventdata, handles)

% --- Executes during object creation, after setting all properties.
function editbox_output_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

% --- Executes on button press in convert.
function convert_Callback(hObject, eventdata, handles)
inputsysnum=get(handles.listbox_input,'value');
outputsysnum=get(handles.listbox_output,'value');
input_string=get(handles.editbox_input,'String');
switch(inputsysnum)
    case(1)
        switch(outputsysnum)
            case (1)
                output_string = bincheck(input_string);
            case (2)
                output_string = bin_2_oct(input_string);
            case (3)
                output_string = bin_2_dec(input_string);
            case (4)
                output_string = bin_2_hex(input_string);
        end
    case(2)
        switch(outputsysnum)
            case (1)
                output_string = oct_2_bin(input_string);
            case (2)
                output_string = octcheck(input_string);
            case (3)
                output_string = oct_2_dec(input_string);
            case (4)
                output_string = oct_2_hex(input_string);
        end
    case(3)
        switch(outputsysnum)
            case (1)
                output_string = dec_2_bin(input_string);
            case (2)
                output_string = dec_2_oct(input_string);
            case (3)
                output_string = deccheck(input_string);
            case (4)
                output_string = dec_2_hex(input_string);
        end
    case(4)
        input_string=char(input_string-32.*floor((sign(123-input_string)+sign(input_string-96))/2));
        set(handles.editbox_input,'String',input_string);
        switch(outputsysnum)
            case (1)
                output_string = hex_2_bin(input_string);
            case (2)
                output_string = hex_2_oct(input_string);
            case (3)
                output_string = hex_2_dec(input_string);
            case (4)
                output_string = hexcheck(input_string);
        end
end
set(handles.editbox_output,'String',output_string);

Contact us